日期:2014-05-18  浏览次数:20456 次

asp.net command更新数据,命令能执行但是数据更新不了
用command更新数据,命令执行没有报错,但是数据却没有更新,具体代码如下:

  string strconn = WebConfigurationManager.ConnectionStrings["istudyconn"].ConnectionString;
  SqlConnection conn = new SqlConnection(strconn);
  conn.Open();
  int idd = Convert.ToInt32(Request.QueryString["id"].ToString());
  string upSql = "update article set title='" + title.Text + "',context='" + neir.Text + "' where id=" + idd;
  SqlCommand comm = new SqlCommand(upSql, conn);  
  if (comm.ExecuteNonQuery() > 0)
  {
  Response.Write("ok");
  }
  else
  {
  response.write("no");
  }
  conn.Close();

注:aspx中有文本框,id 分别为 title 和neir 
实在是搞不明白是哪里错了,按照我的调试,好像是upsql语句错误,不能读到文本框中的内容,如果改成固定的字符,如
 string upSql = "update article set title='yyyyy',context='yyyyy' where id=" + idd;
则运行正常,实在不解啊,还望高手指点!

------解决方案--------------------

Page_load 事件中 添加
if ispostback=false then



end if 
然后试一下