r_keya

r_keya

  • NA
  • 9
  • 0

Updating database from an editable datagrid

Jul 13 2004 12:41 AM
I am trying to use an editable datagrid to update data. When I try to debug it, the error is that it cannot find the ds and the da in private void btnChange_Click which is at the bottom of my code. Now I understand that these both are seperate private buttons with seperate event handlers. How do you then actually update the changed data? I read the MSDN site and they do the same thing. Here is my code: private void btnSubmitChange_Click(object sender, System.EventArgs e) { try { OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open();//conn.CreateCommand(); if(lstBxSelectData.SelectedItem.ToString()=="Tbl_Questions") { string getData = "SELECT * FROM Tbl_Questions"; OleDbDataAdapter da = new OleDbDataAdapter(getData,conn); DataSet ds = new DataSet(); da.Fill(ds); dtGrdData.SetDataBinding(ds,"Tbl_Questions"); ds.Tables["Tbl_Questions"].DefaultView.AllowEdit= true; ds.Tables["Tbl_Questions"].DefaultView.AllowDelete = true; } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void btnChange_Click(object sender, System.EventArgs e) { OleDbCommandBuilder bd = new OleDbCommandBuilder(da); dtGrdData.Update(ds,"Tbl_Questions"); }

Answers (3)