string uptcmd="update login_db set name_ID=@name1,psw_ID=@psw1 where dept_ID=@dept_ID";
OleDbConnection myconnection=new OleDbConnection(CnnString);
OleDbCommand mycommand=new OleDbCommand(uptcmd,myconnection);
mycommand.Parameters.Add(new OleDbParameter("@dept_ID",OleDbType.VarChar,50));
mycommand.Parameters["@dept_ID"].Value=DataGrid1.DataKeys[(int)E.Item.ItemIndex];
mycommand.Parameters.Add(new OleDbParameter("@name1",OleDbType.VarChar,50));
mycommand.Parameters["@name1"].Value=((TextBox)(E.Item.Cells[3].Controls[0])).Text;
mycommand.Parameters.Add(new OleDbParameter("@psw1",OleDbType.VarChar,50));
mycommand.Parameters["@psw1"].Value=((TextBox)(E.Item.Cells[4].Controls[0])).Text;
mycommand.Connection.Open();
mycommand.ExecuteNonQuery();
mycommand.Connection.Close();
还有就是E.Item.Cells[4].Controls[0],这里,这个Cells[]和Controls[]分别是做什么的,由什么决定?

解决方案 »

  1.   

    捕捉一下出错信息看看                           try
    {
    mycommand.Connection.Open();
    mycommand.ExecuteNonQuery();
    mycommand.Connection.Close();
    } catch(OleDBException)
    {
    .... }E.Item.Cells[4].Controls[0],
    当前行的第5列(是个模版列)中第一个控件(不过我印象中control的index似乎从1开始)
      

  2.   

    我试了,没有提示错误,但是点update后,textbox里面显示我修改过的数据又变回了更改以前