表中ID是主键,用来验证数据的3行javascript显示的数据也完全正确,“更新成功”的提示也出现了,怎么就是没更新呢???而且删除按牛功能是完全正确的
=================================DATAGRIA的HTML属性代码==================================
<asp:datagrid id="DataGrid1" runat="server" Width="800px" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="4" AutoGenerateColumns="False" AllowPaging="True" OnEditCommand="edit" OnCancelCommand="cancle" OnUpdateCommand="update"
OnDeleteCommand="delete" DataKeyField="ID">
============================================================================================================编辑段的代码==================================================
public void edit(Object sender,DataGridCommandEventArgs e)
{
        this.DataGrid1 .EditItemIndex =(int)e.Item .ItemIndex ;
//this.BindGrid ();
}
=====================更新段的代码=======================================================
public void update(Object sender,DataGridCommandEventArgs e)
{
 
            string strCommand="UPDATE C_DICTIONARY SET name=@name,Bond_field_name=@Bond_field_name where ID=@ID" ;
System.Data.OleDb.OleDbCommand comm=new OleDbCommand (strCommand,conn );
comm.Parameters .Add (new OleDbParameter("@ID",OleDbType.VarChar,10) );//隐藏列,用来确定修改的行数
comm.Parameters .Add (new OleDbParameter("@name",OleDbType.VarChar,10) );
comm.Parameters .Add (new OleDbParameter("@Bond_field_name",OleDbType.VarChar,10) );
           
comm.Parameters ["@ID"].Value =this.DataGrid1 .DataKeys [(int)e.Item .ItemIndex ];//用唯一列(隐藏)定位修改的行
comm.Parameters["@name"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
comm.Parameters["@Bond_field_name"].Value=((TextBox)e.Item.Cells[3].Controls[0]).Text;
Response.Write ("<script language=javascript> alert('"+comm.Parameters ["@ID"].Value +"')</script>");
Response.Write ("<script language=javascript> alert('"+comm.Parameters["@name"].Value +"')</script>");
Response.Write ("<script language=javascript> alert('"+comm.Parameters["@Bond_field_name"].Value +"')</script>"); conn.Open ();
try
{
comm.ExecuteNonQuery ();
Response.Write ("<script>alert('更新成功!');</script>");
this.DataGrid1 .EditItemIndex =-1;
}
catch(System.Data.OleDb .OleDbException ex)
{
Response.Write ("<script>alert('更新失败!"+ex.Message +"');</script>");
}
conn.Close ();
             this.BindGrid (); }

解决方案 »

  1.   

    更新之后要重新绑定DataGrid才能看到更新后的数据
    也就是调用this.BindGrid ();
      

  2.   

    显示一下更新用的SQL,看看是否正确。
      

  3.   

    对阿,我有 this.BindGrid ();
    ,但是数据库和显示的都没有更新,而且我不用参数改用常量也不能更新
      

  4.   

    是不是pageload中在postback也绑定了导致你读到的textbox中的数据是原来的
      

  5.   

    =====================Page_Load==================的代码,传进去得个值都是正确的
    private void Page_Load(object sender, System.EventArgs e)
    {

    // 在此处放置用户代码以初始化页面

    conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("operation1.mdb")+"");
    if(!Page.IsPostBack )
    {
    this.BindGrid ();
    this.ButDelete .Attributes.Add("onclick","javascript:return confirm('确定删除吗?')");//删除前的确认
     

    }
    }
      

  6.   

    where ID=@ID"哪来的。。
    改成这样写试试
    where id='"+DataGrid1.DataKeys[(int)e.Item.ItemIndex]+"'
      

  7.   

    try
    {
    comm.ExecuteNonQuery ();
    Response.Write ("<script>alert('更新成功!');</script>");
    this.DataGrid1 .EditItemIndex =-1;
             绑定事件加在这里,不是加在外面啊!!!!this.BindGrid();
             }
      

  8.   

    因为你写的语句CONN都CLOSE了。还能再绑定吗?把绑定事件添加到更新成功那里!!
      

  9.   

    xieyun9958(ぁ唯有魅影ぁ)  我试试,成功就等着接分吧
      

  10.   

    conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("operation1.mdb")+"");conn是在哪里定义的?运行不报错吗?把连接分别写到每个事件里吗?我怎么看你的代码,好象更新事件里的conn.open就应该报错了,,把连接加到update和bindgrid的里面,不要放在page_load里面!
      

  11.   

    comm.Parameters ["@ID"].Value =this.DataGrid1 .DataKeys [(int)e.Item .ItemIndex ].ToString();
      

  12.   

    我的连接是防在page_load里的,我放到事件里再试试,可问题是删除操作是完全正常的啊
      

  13.   

    OK了,使阿ACCESS的问题,我改用SQL数据库,就改了连接字符串,程序其他一点也没动,就OK了,真怪啊