当前位置: 代码迷 >> SQL >> 求各位大侠看小弟我修改数据库错哪了吧、
  详细解决方案

求各位大侠看小弟我修改数据库错哪了吧、

热度:113   发布时间:2016-05-05 15:27:15.0
求各位大侠看我修改数据库哪里错了吧、、
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+"'";

为这些单引号。其它如果仍有问题自己加一下。
  相关解决方案