473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
5 2988
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
3,256 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

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

Similar topics

10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
4
by: Steve Teeples | last post by:
I have a form with two DataGridView controls. The form has linked to it an Access database with just two tables. The second table contains unique "child" data having a one-to-one relationship...
7
by: Greg P | last post by:
I'm new to VS2005 and want to simply update my data with the dataGridView that was generated when I draged my query from the Data Sources Pane. I think I may need to create a Data Adaptor but I'm...
1
by: David | last post by:
I have a realtime stock quote system developed where I am updating a typed dataset with realtime quotes. I want my DataGridView control to show green forecolor when a price moves up and red...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
1
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
1
by: weird0 | last post by:
How can i update the data in my database directly through datagridview....? Can anyone tell me the appropriate links and what is the exact event in datagridview that handles it and some explanation...
7
by: Bill Schanks | last post by:
VB.NET 2005 SQL Server 2000 I have a datagridview that users will update. When there are only a few records the update is fine. However when they update 100-200 of the rows the udpate can take...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.