我现在需要更新数据库内容,但是总是更新不了,请大家帮我看看!谢谢!
private void newsok_Click(object sender, System.EventArgs e)
{
string class11=DropDownListclass1.SelectedItem.Value;
string class22=Dropdownlistclass2.SelectedItem.Value;
string class33=Dropdownlistclass3.SelectedItem.Value;
string jqtitle1=Request.Form["jqtitle"].Trim();
            string jqnews1=FCKeditor1.Value;
string jqauthor1=Request.Form["jqauthor"];
string strUpdate="UPDATE jq_news SET jqtitle='"+jqtitle1+"',jqnews='"+jqnews1+"',jqauthor='"+jqauthor1+"',class1='"+class11+"',class2='"+class22+"',class3='"+class33+"' where id="+b+"";
try
{
SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand MyCommand = new SqlCommand(strUpdate,MyConnection);
MyConnection.Open();
MyCommand.ExecuteNonQuery();
Info.Text="数据已经修改!";
jqtitle.Text="";
jqauthor.Text="";
FCKeditor1.Value="";
MyConnection.Close();
Response.Redirect("managenews.aspx");
}
catch(Exception ee)
{
Info.Text="发生错误:"+ee.Message;
}
}
我哪里写的不对吗?

解决方案 »

  1.   

    为什么写sql语句时set field = "+field+"?每个字段数据类型都支持+存储吗?好像是多余的...
      

  2.   

    加断点调试一下,把其中string strUpdate的值复制出来放到查询分析器中执行一下,看能不能执行。
      

  3.   

    看起来象是没有错,我是新手,我写的时候总要加上 command的add变量事件,不知道不加是不是可以!!
      

  4.   

    我现在感觉update不起作用可能是因为我重新做了机器,重新安装了Visual Studio,我想请问大家我的项目应该如何重新加载,这个问题解决了,我的问题就解决了。
      

  5.   

    第一是要清楚update..这是更新操作.是数据库里有数据现在更新..要是没有数据就用insert第二 where id="+b+"";你的id是什么类型的啊??数值型的??否则这样用是不行.你用了catch 有什么异常吗???要是没有建议你监视一下sql语句.放到查询分析器中.