com.ExecuteNonQuery();附近有语法错误

protected void Button2_Click(object sender, EventArgs e)
{
string id = this.TextBox1.ToString();
string Pwd = this.TextBox2.ToString();
string Ph = this.TextBox3.ToString();
string card = this.TextBox4.ToString();
string str = "Data Source=.\\SQLEXPRESS;AttachDbFilename=F:\\毕业设计\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True";
SqlConnection Con = new SqlConnection(str);
Con.Open();
string sqlstr = "insert into User(User_id,Password,Phone,ID_card)values('" + id + "','" + Pwd + "','" + Ph + "','" + card + "')";
SqlCommand com = new SqlCommand(sqlstr,Con);
com.ExecuteNonQuery();
Response.Redirect("Default.aspx");
}
}

把你的sqlstr打印出来放到数据库上执行看好使么。追问

肯定不行啊··我前面定义字符串是在VS上弄的 id这些应该在SQL上面没有定义是执行不了的吧

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-03
SqlCommand com = new SqlCommand(sqlstr,Con); 在这行下断点,把sqlstr的内容拷贝出来,到SQL管理器中执行一下,就知道是哪儿错了,应该是你的SQLSTR拼接后语法错误本回答被网友采纳
相似回答