changes in a datagrid?
-
Can anyone help me get my datagrid to update it's data? I’ve populated a datagrid with the contents of a table from an access database, but the problem I’m running into is when I change a value in the grid it’s not being saved/updated/deleted in the database. Has anyone ever done anything like this before? I've seen some examples in sql server and one or two things in access from the web but none of them seem to work correctly. ;P Thanks
-
Can anyone help me get my datagrid to update it's data? I’ve populated a datagrid with the contents of a table from an access database, but the problem I’m running into is when I change a value in the grid it’s not being saved/updated/deleted in the database. Has anyone ever done anything like this before? I've seen some examples in sql server and one or two things in access from the web but none of them seem to work correctly. ;P Thanks
-
Manster wrote: Can anyone help me get my datagrid to update it's data? Looks like nobody answered your earlier post. ;) Anyway I will try. Did you check the RowState property "DataRowState.Modified" value? Don't :beer: and drive.
-
I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.
-
Post your code snippet, so that others can identify the problem. Is the data grid on a WebForm or Windows Form? Don't :beer: and drive.
My datagrid is on a windows form. This is the code that is in the m_DataGrid_Validate() grid event when you close the application once some data has been changed in the grid. DataSet dsUpdate = m_MyDataSet.GetChanges(); OleDBDataAdapter dataAdapter = new OleDBDataAdapter ("Update Authors set ...", m_sConn); OleDBCommandBuilder cb = new OleDBCommandBuilder(dataAdapter); dataAdapter.UpdateCommand = cb.GetUpdateCommand(); dataAdapter.Update(dsUpdate, "Authors"); dsUpdate.AcceptChanges();
-
I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.
Try this: change the button1 to your update button name dataSet21 to your DataSet name. oleDbDataAdapter1 to your DataAdapter name. Products to your table name. I used Northwind database via MSDE and it worked.
private void button1_Click(object sender, System.EventArgs e) { if (dataSet21.HasChanges()) { try { int nModified; nModified = oleDbDataAdapter1.Update(dataSet21.Products); string strOutput; strOutput = "Modified " + nModified + " products(s)"; MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Update failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
Don't :beer: and drive. -
Try this: change the button1 to your update button name dataSet21 to your DataSet name. oleDbDataAdapter1 to your DataAdapter name. Products to your table name. I used Northwind database via MSDE and it worked.
private void button1_Click(object sender, System.EventArgs e) { if (dataSet21.HasChanges()) { try { int nModified; nModified = oleDbDataAdapter1.Update(dataSet21.Products); string strOutput; strOutput = "Modified " + nModified + " products(s)"; MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Update failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
Don't :beer: and drive.I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it? Thanks for all your help!
-
I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it? Thanks for all your help!
Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.
-
Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.
-
Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.