首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview更新时取到的还是原数据,该如何处理

2012-01-08 
gridview更新时取到的还是原数据代码如下protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdat

gridview更新时取到的还是原数据
代码如下
  protected   void   GridView1_RowUpdating(object   sender,   GridViewUpdateEventArgs   e)
        {
                OracleConnection   conn   =   new   OracleConnection( "Data   Source=xx;User   ID=xx;Password=xx; ");
                string   strSQL   =   "update   UNIT   set   UNIT_ID= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim()   +   " ',UNITID= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim()   +   " ',UNAME= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()   +   " ',UCHIEF= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim()   +   " ',POST= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim()   +   " ',PHONE= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim()   +   " '   where   UNIT_ID= ' "
                        +   GridView1.DataKeys[e.RowIndex].Value.ToString()   +   " ' ";
                OracleCommand   cmd   =   new   OracleCommand(strSQL,   conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                GridView1.EditIndex   =   -1;
                GV1();
        }
在SQL语句处设了断点的,可见没取到更改后的值

[解决办法]
GridView1有设置DataKeyNames为表的主键么?

热点排行