也不是不执行,我已经用断点跟踪过了,都执行了,可是数据库的记录就是没更改,这是怎么
回事啊?(我用的acess数据库)
代码如下:
private void Button1_Click(object sender, System.EventArgs e)
{
   if (Page.IsValid) 
    {
OleDbConnection cn;
OleDbCommand cmd;
string sqlstr;
sqlstr="update worker set subject=@subject,content=@content,type=@type where id=@id";
cn=new OleDbConnection(Session["strConn"].ToString());
cmd=new OleDbCommand(sqlstr,cn);
string work_subject=subject.Text.Trim();
string content0=content.Text;
string work_content=content0.Replace("\n", "<br>");
cmd.Parameters.Add("@id",OleDbType.TinyInt,8).Value=Request["id"];
cmd.Parameters.Add("@subect",OleDbType.VarChar,50).Value=work_subject;
cmd.Parameters.Add("@content",OleDbType.VarChar,1000).Value=work_content;
cmd.Parameters.Add("@type",typeList.SelectedValue);
try
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Msg.Text="更新成功!";
}
catch(Exception ex)
         {
Msg.Text="因以下原因,数据更新失败:<br>"+ex.Message;
}
}

}
  我执行了之后,已经提示‘更新成功’,可是数据库里的记录就是没改?这是怎么回事啊?

解决方案 »

  1.   

    update worker set subject=@subject,content=@content,type=@type where id=@id
    这一句sql放到access里面带上数值,看看能直接运行么?
      

  2.   

    调试确定几个参数都有值如果都有值,把值代入sql语句中然后在access中运行看看
      

  3.   

    cmd.Parameters.Add("@id",OleDbType.TinyInt,8).Value=Request["id"];
    单步调试,看看你的Request["id"]值是否和要更新的记录匹配!
      

  4.   

    string work_subject=subject.Text.Trim();
    string content0=content.Text;
    string work_content=content0.Replace("\n", "<br>");跟踪一下是否得到值啦!
    因为你是update咯
      

  5.   

    string id = Request["id"];
    cmd.Parameters.Add("@id",OleDbType.TinyInt,8).Value = id;
    看看你id的值是否与数据库对应。
    感觉应该是找不到对应的id
    所以更新失败
      

  6.   

    直接用SQL语句,不要用参数了
    例如:
    update worker set subject='" + work_subject + "',content=@content,type=@type where id=@id
      

  7.   

    打印id有没有传过来??
    response.write Request("id");
    .........end
      

  8.   


    在cmd.Parameters.Add("@id",OleDbType.TinyInt,8).Value=Request["id"]处设断点逐步调试;
    在“自动窗口”栏中查看调试后"@id"的值是否是你要修改记录的ID,如果id的值为空的话说明根本就没有id值传过来,这样你肯定修改不成功。另外再查看一下调试后"@subect","@content","@type"的值是否已经变为你所输入的值。
      

  9.   

    可能你根本没有得到ID,所以,数据库里也就没有要更新的纪录了....你可以将SQL的参数去了,看会不会有结果.如:Update worker set subject='xx',content='yy',type='tt' where ID=5这样看看.
      

  10.   

    还是直接用sql语句吧
    参数又不是很多!
      

  11.   

    看看数据库的权限 是否是everyone完全控制
      

  12.   

    经过大家的指点,我多方调试,最后把sqlstr那句
    改成sqlstr="update worker set subject='"+work_subject+"',content='"+work_content+"',type="+type+" where id=@id";
    就好了看来是
    cmd.Parameters.Add("@subject",OleDbType.VarChar,50).Value=work_subject;
    cmd.Parameters.Add("@content",OleDbType.VarChar,1000).Value=work_content;
    cmd.Parameters.Add("@type",typeList.SelectedValue);
    这里的值没传进去啊,大家能帮我看看这几句哪里有毛病吗?