代码如下
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为表的主键么?