如题
最好有代码
谢谢
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=msdaora;Data Source=TEXT;User ID=SA;Password=123");//连接数据库
conn.Open();
try
{
string sql = "update table1 set col1='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim()
+ "',col2='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()
+ "',col3='"+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim()
+ "' where col1='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
System.Data.OleDb.OleDbCommand oledbCommand = new System.Data.OleDb.OleDbCommand(sql, conn);
oledbCommand.ExecuteNonQuery();
GridView1.EditIndex = -1;
}
catch (Exception ex)
{
UIUtility.Alert(ex.Message, this);//错误提示
}
finally
{
conn.Close();//关闭数据库连接
conn = null;
}
GridView1.EditIndex = -1;
Bind();
}