我的客戶表customer字段類型為varchar型的 ,但是我在插入數據時不能插入字母,符號,只能插入數字類型的字符串
比如插入 “lly.sfa”就不行,但是插入“54215642”就可以 。下面是我的代碼
try
{
string username = TextBox1.Text;
string password = TextBox2.Text;
string againpassword = TextBox3.Text.;
string phonenumber = TextBox4.Text.();
Random ran = new Random();
int id = Convert.ToInt32(string.Format("{0:ddHHmmss}", DateTime.Now) + ran.Next(0, 10));
string sqlselete = "select count(*) from customer where customer_name=" + username;
dataOperate sqlopereat = new dataOperate();
int num = sqlopereat.IsData(sqlselete);
if (num == 0)
{
try
{
string sqlupdata = "insert into customer(customer_id,customer_name,customer_password,customer_phone,customer_level) values(" + id+"," + phonenumber+","+username+","+password+","+ "5) ";
//bool a=sqlopereat.Insert(sqlupdata);
//if (a==true)
//{
// Response.Write("恭喜 注冊成功");
//}
bool result = sqlopereat.AdlData(sqlupdata);
if (result == true)
{
Response.Write("恭喜 注冊成功");
}
}
catch (Exception)
{
throw;
}
}
}
catch (Exception)
{
throw;
}
}
數據庫連接沒有問題 我用的是VS2015內置的數據庫 是這個的問題嗎?
你的sql語句中拼接,字符串類型的變量外面要加上單引號。