Save Updated Records to SQL Server table via Datagridview

rmclean

Member
Joined
Apr 15, 2010
Messages
6
Programming Experience
1-3
I have a datagridview control on a form where I want a user to be able to enter one or multiple records that will then be saved to a table in SQL server when a button is clicked. The datasource is set programmatically when a different button is clicked that enables the groupbox where the datagridview is located. I've found several posts that talk about tablemappings and using dataset.update but I can't get it to work. If anyone has a code sample that does this, I'd be very happy to see it. Thanks for any help.
 
There is no DataSet.Update. It's quite simple, and the DataGridView has pretty much nothing to do with it. You use a DataAdapter and a DataTable. You call Fill on the adapter to populate the table with data from the database and you call Update on the adapter to save the changes in the table back to the database. What happens in between has nothing to do with the data access. You can bind the DataTable to a DataGridview and have the user edit it fine, but whether you do that or edit in code or whatever, that doesn't change how the data access is done.

So, I suggest that you have a look at these examples of mine:

Retrieving and Saving Data in Databases

Note that, if you don't want to actually get any data from the database in the first place, you can call FillSchema instead of Fill to build the DataTable schema without populating it. Alternatively, you can build the DataTable schema yourself.
 
Back
Top