当前位置: 代码迷 >> ASP.NET >> 再问: 数据库不能更新有关问题?(待)
  详细解决方案

再问: 数据库不能更新有关问题?(待)

热度:963   发布时间:2013-02-25 00:00:00.0
再问: 数据库不能更新问题??(在线等待)
这个问题困扰本人两天了.昨天在CSDN请教过.得到网友们的热心回答,但还是不能解决.开始我是一下想更新两个表结果不成功.于是
我改成更新一个表..
思路是.先将数据表中的相关数据读出来放在textbox中去.然后再对文本框中的内容修改.放到数据库中.
.代码如下:using (SqlConnection con = db.connection())
  {
  SqlCommand cmd = new SqlCommand("update depuser set depuser ='"+text1.Text+"',text2.text = '"+this.deppass2.Text+"',text3.text= '"+ this.username3.Text+" where departmentid="+int.Parse(Session["departmentid"].ToString()),con);
  try
  {
  con.Open();
  cmd.ExecuteNonQuery();
  Response.Write("<script>window.alert('操作成功!')</script>");
  }
  catch (Exception ex)
  {
  throw new Exception(ex.Message, ex);
  Response.Write("<script>window.alert('操作失败!')</script>");
  }
结果提示"操作成功!",但是数据库中的数据并没有改变.我试过用更新存储过程.结果依然是一样的.


------解决方案--------------------------------------------------------
string sql="update depuser set depuser = '"+text1.Text+" ',text2.text = '"+this.deppass2.Text+" ',text3.text= '"+ this.username3.Text+" where departmentid="+int.Parse(Session["departmentid"].ToString()
把sql打出来看看.
  相关解决方案