Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating Database Table with DataGridView

Posted on 2009-06-26
7
Medium Priority
?
358 Views
Last Modified: 2012-05-07
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:

dgvUserList.Update
dgvUserList.Refresh

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,
Fulano
0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24726339
Try this


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

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 24726398
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.

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

0
 
LVL 1

Accepted Solution

by:
hearts earned 2000 total points
ID: 24726475
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:
http://msdn.microsoft.com/en-us/library/ms971491.aspx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mr_Fulano
ID: 24726523
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,
Fulano
0
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24726528
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
0
 

Author Comment

by:Mr_Fulano
ID: 24731569
Thanks BMKESHAV. I appreciate the help!!!
0
 

Author Comment

by:Mr_Fulano
ID: 24731574
BMKESHAV, did you say there was a link attached? I can't see one attached to your post.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question