467,074 Members | 844 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

C#.Net Datagridview - updating the dataset with datagridview

Hello All,

Here's what I'm trying to do:

I'm loading a datagridview with data from a dataset. I want to be able to update data in the datagridview and then save changes back to the dataset or database. I'm not sure how to do this! Any ideas?

Thanks in advance all....

Sreeni
Aug 7 '08 #1
  • viewed: 2705
Share:
5 Replies
Hello All,

Please anyone help me asap.

Here's what I'm trying to do:

I'm loading a datagridview with data from a dataset. I want to be able to update data in the datagridview and then save changes back to the dataset or database. I'm not sure how to do this! Any ideas?

Thanks in advance all....

Sreeni
Aug 7 '08 #2
Curtis Rutland
Expert 2GB
There are hundreds of tutorials on this on the web. Do a little bit of searching.

EDIT:
Also, do not double post your questions. It clutters up the forum and has no benefit to you whatsoever. If you feel that your thread has been overlooked or neglected you can "bump" it back to the top of the page by replying to it. If you can't find your old thread, look at the top of the page under "My Stuff". Click the My Subscriptions link.

But do not post your questions twice. I have merged your threads.

MODERATOR
Aug 7 '08 #3
Yes there are hundreds of tutorials on this on the web and I've looked at a lot of them. However I've not been able to find one yet that handles this the way I'd like to do it.

I have a DataGridView on a VB.NET form. I can type in new data rows and then hit a button that runs the following line of code:
Me.XYZTableAdapter.Fill(Me.XyzDataSet.XYZ)

That works fine and the new row is there after I close and restart the program. However if I change the data in one or more cells in the existing rows, I keep getting the following error message:
System.InvalidOperationException: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

I could write some code to take the whole table and update every row whether it was changed or not. Or I could isolate the changes and handle them individually. Given the appearance and functionality of the DataGridView and also the fact that it handles this OK for adding data, I'm surprised that such updates wouldn't work without a lot of extra code.
Aug 10 '08 #4
Here's the answer. (I found pieces of it in a number of different discussion groups, but the responses weren't been detailed enough to be really helpful.)

Add a primary key to the database table if it doesn't have one
[in form designer window] Right-click the [xxx]TableAdapter in the tray below the form>click Edit Queries in DataSet Designer
[*] Right-click where its says [xxx]TableAdapter (row in the middle of the little form in left center of window)>
[*] click Add Query>
[*] Leave Use SQL statements selected (or click it if not selected)>Next
[*] click Update>
[*] Next>
[*] Next>
[*] Next>
[*] Finish

* in next form

It would be nice if the documentation on MSDN spelled this out in more detail.
Aug 10 '08 #5
Hello All,

Please anyone help me asap.

Here's what I'm trying to do:

I'm loading a datagridview with data from a dataset. I want to be able to update data in the datagridview and then save changes back to the dataset or database. I'm not sure how to do this! Any ideas?

Thanks in advance all....

Sreeni

You can bind the dataset to the datagridview by setting the dataset as the data source..
Aug 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Henok Girma | last post: by
4 posts views Thread by Steve Teeples | last post: by
1 post views Thread by David | last post: by
2 posts views Thread by bob@datasync.com | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
1 post views Thread by weird0 | last post: by
7 posts views Thread by Bill Schanks | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.