使用GridView直接编辑更新数据时,出现一个让我迷惑的问题:
GridView编辑更新后绑定的数据仍是未更新前的数据,而再次点击编辑时才显示更新后的数据,但当后台数据是Oracle时,却不会发生这种情况,这是为什么?
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + base.Request.PhysicalApplicationPath + ConfigurationManager.AppSettings["AccessFile"]);
string sqlstr = "update ComputerList set Machine_ID='"
+ ((TextBox)GridView1.Rows[GridView1.EditIndex].Cells[1].Controls[0]).Text + "' where Computer_Name='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
conn.Open();
cmd = new OleDbCommand(sqlstr, conn);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
bind(Session["GetDataSQL"].ToString());
}
public void bind(string GetDataSQL)
{
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + base.Request.PhysicalApplicationPath + ConfigurationManager.AppSettings["AccessFile"];
conn = new OleDbConnection(connStr);
conn.Open();
ds = this.StoneFunction.GetDSFromAccess(GetDataSQL, conn);
DataView view = ds.Tables[0].DefaultView;
GridView1.DataSource = view;
GridView1.DataKeyNames = new string[] { "Computer_Name" };
GridView1.DataBind();
conn.Close();
}
public override void VerifyRenderingInServerForm(Control control)
{
}