我在用DataGrid里的D UpdateCommand 能成功更新数据,但是在点去更新按钮后然后再手动在IE上刷新一下页面才能正常显示出更新后的数据!public void DataGrid_UpdateCommand(object sender,DataGridCommandEventArgs e)
{
string Mem_name = ((TextBox)e.Item.Cells[2].Controls[1]).Text.Trim();

string Mem_email =((TextBox)e.Item.Cells[3].Controls[1]).Text.Trim(); string Ser_title =((TextBox)e.Item.Cells[4].Controls[1]).Text.Trim(); string Ser_solution = ((TextBox)e.Item.Cells[5].Controls[1]).Text.Trim(); string strSQL = "Update Ser_answ Set Mem_name='" + Mem_name + "', Mem_email='" + Mem_email + "', Ser_title='" + Ser_title + "' ,Ser_solution = '" + Ser_solution + "' Where " + myDataGrid.DataKeyField + "=" + myDataGrid.DataKeys[e.Item.ItemIndex]; sql_execute(strSQL,strConnectionString); this.myDataGrid.EditItemIndex = -1; BindList();
}private void sql_execute(string sql,string connectionstring)
{
OleDbConnection conn  = new OleDbConnection(connectionstring);
if(conn.State ==  ConnectionState.Closed)
{conn.Open();}
OleDbCommand objCmd = new OleDbCommand(sql,conn);
objCmd.ExecuteNonQuery();
}

解决方案 »

  1.   

    恩。。需要手动刷新 说明你更新数据库后绑定没成功
    检查下BindList();是否没考虑完整
      

  2.   

    单步调试,试一下有没有传进去了值,然后注意一下你在Page_Load()中的代码是怎么写的??每次页面刷新后有没有重新绑定数据源?????
      

  3.   

    还是不知道如何处理,我把我的bindlist 发出来
    private void BindList()
    {
    if(Convert.ToString(this.Session["bindsql_answer"]) == "")
    {
    this.Session["bindsql_answer"] = "Select * From Ser_answ order by Ser_id desc";
    }
    string bindsql_answer = Convert.ToString(this.Session["bindsql_answer"]);
    OleDbDataAdapter objCmd = new OleDbDataAdapter(bindsql_answer, strConnectionString);
    DataSet DS = new DataSet();
    objCmd.Fill(DS,"数据");
    DataTable myTable = new DataTable();
    myTable = DS.Tables["数据"];
    int icount = myTable.Rows.Count;
    this.icount.Text = icount.ToString();
    DataView dv = new DataView(myTable);
    dv.Sort  = SortField.Value;
    this.myDataGrid.DataSource=dv;
    this.Response.Write(bindsql_answer);
    myDataGrid.DataBind();
    }
      

  4.   

    我以前用VB加access写的时候也有这个问题,后来改sql server就没有这个问题,现在又要用到access问题还是出现了