DataGridView: how to save updates to the database.

I'm using Visual Studio 2008, Visual Basic.Net.
I have a DataGridView. It is bound using an adapter. It shows the data, and I've set the properties to allow all updates.
When the user keys in changes, they are just lost when the application closes. They don't commit to the database.
What am I missing? What would be the simplest code to tell the DataGridView to commit changes (update, insets, deletes) to the table?
Who is Participating?
Jorge PaulinoIT Pro/DeveloperCommented:
This is an example that I have post and uses Microsoft Access as datasource, but you can do the same to SQL or other database.
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
There are many ways to do this, row by row, or at one step. The key is to use a dataadapter.
Have a look to this article:

if your datagrid is related to a single table, could be done with easy at form's close event, if you have previously filled your datatable as:

SqlDataAdapter da=new SqlDataAdapter("select * from yourtable", yourconn);
SqlCommandBuilder cb=new SqlCommandBuilder(da);
DataSet ds = new DataSet();

then you just have to do:

da.Update();  // copy all the changes to ds to the database
mcolesonAuthor Commented:
Thank you jpaulino and jaime_olivares.
I am now able to update the table from the datagridview.
i just assumed that if I built the datagridview using Microsoft's templates, I could update without overriding the datasource.  Oh well.
Mission accomplished.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.