Updating Database Table with DataGridView

Hi, I'm using VB 2005, WinForms. I have a database Table we can call (UsersList). I have a DataTable called (dtUsers) in my code that works with a DataAdapter. Together they fill a DataGridView for me to display my list of Users. - That much works well.

I would like to allow my users to make changes (Edits) to the data that they see in  the DataGridView. My problem is how do I execute the "Update" of changes back to the Table from the DataGridView.  And have the DataGridView refresh itself.

In other words, if I do the following it does not work:


I would like to provide my users a button for them to click and be able to save any modifications made to the data they see in the DatGridView.

Thanks for your help,
Who is Participating?
heartsConnect With a Mentor Commented:
I think you are not writing the commandbuilder code for dataadapter to update the records back in database. Or might be missing some columns in commandbuilder update query thats why there comes an error.
This will help you for more details:
Try this

da.Update(dtUsers) '<--- Update the dtUsers using the dataadapter.
dtUsers.AcceptChanges() '<---- Accepts the changes made.

Open in new window

Mr_FulanoAuthor Commented:
Hi Jack,
I'm getting this error at the first line of code you provided [da.Update(dtUsers)].
Obviously, I changed the adapter and table names to be correct with my code.

Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Mr_FulanoAuthor Commented:
Thanks, I figured out what was wrong with my original code, so I was able to fix my problem and learned a some new tricks form you along the way.

Thanks again,
pl.see the attached aspx.net/vb.net code.
This will help you, i think method is same for win form datagrid or aspx page datagrid.
Where every i have used mysql you can use Sql property.

Bm keshav
Mr_FulanoAuthor Commented:
Thanks BMKESHAV. I appreciate the help!!!
Mr_FulanoAuthor Commented:
BMKESHAV, did you say there was a link attached? I can't see one attached to your post.
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.