using(SqlCommand cmd = con.CreateCommand())
{
String name = "";
if (Session["username"] != null)
{
name = Session["username"].ToString();
cmd.CommandText = "update Information set UserID = " + TextBox4.Text + ","
+ "Name =" + TextBox2.Text + ","
+ "sex =" + RadioButtonList1.SelectedItem.Text + ","
+ "Age =" + TextBox5.Text + ","
+ "Tel =" + TextBox6.Text + "where UserName =" + name;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
我的Session里面保存的是zhang这个ID号,我想在另外一个表中找到ID号为zhang的修改它的信息,结果调试的时候出现不存在列名“zhang”无效。不知道是哪错了。(我的另一个表中存在ID号为zhang的这一行)
本来没学过数据库,因为老师布置的一个作业,要用到数据库,只能硬着头皮上了,球各位大侠帮帮忙、、
------解决方案--------------------
cmd.CommandText = "update Information set UserID = '" + TextBox4.Text + "',"
+ "Name =" + TextBox2.Text + ","
+ "sex =" + RadioButtonList1.SelectedItem.Text + ","
+ "Age =" + TextBox5.Text + ","
+ "Tel =" + TextBox6.Text + "where UserName ='" + name+"'";
为这些单引号。其它如果仍有问题自己加一下。