473,491 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to update DataGrid's data to the DB using DataSet ??

To all,

I am writing a C# application; I've a DataGrid to show and edit data;
then I tried to update the updated data by calling ADO_Adapter.update
(ADO_DataSet, "TableName");

But it pop up a DBConcurrencyException!

Anyone get ideas on how to properly use DataGrids and DataSets together
???

PS. I can post the code if you guys need to know

Thanks!
From Jason (Kusanagihk)


Nov 17 '05 #1
2 4052
To all,

I've got one more question....
It seems that DataSet is a set of offline data dragged from DB; so is
it really proper to populate a DataGrid when the data shown can still
be modified? (since it's offline and not the Adodc components from the
VB6 era....)

So, if I really can't update the DataSet directly, should I update DB
info by overriding a DataGrid's eventHandler(s) ??? like the datacell's
clicking event ???

Thx!
From Jason (Kusanagihk)


Nov 17 '05 #2
To all,

I've solved most of the problem now!
PS. hope this message helps those who met DBConcurrencyException like
my case!

1) I've linked up the DataSet and DataGrid by using SetDataBindings
method
2) I've added a button to handle all updates within the DataGrid
3) within that button's code, I've setup the required SqlCommand like
this
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. if (this.mADO_CommandUpdateDGCustomers == null)
  4. {
  5. this.mADO_CommandUpdateDGCustomers = new SqlCommand
  6. ("Update Customers set " +
  7. "CompanyName=@companyName, ContactName=@contactName
  8. where CustomerID=@customerID",
  9. mADO_Connection);
  10.  
  11. oParam = new SqlParameter ("@companyName",
  12. System.Data.SqlDbType.VarChar, 255, "CompanyName");
  13. oParam.SourceVersion =
  14. System.Data.DataRowVersion.Current;
  15. mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
  16.  
  17. oParam = new SqlParameter ("@contactName",
  18. System.Data.SqlDbType.VarChar, 255, "ContactName");
  19. oParam.SourceVersion =
  20. System.Data.DataRowVersion.Current;
  21. mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
  22.  
  23. oParam = new SqlParameter ("@customerID",
  24. System.Data.SqlDbType.VarChar, 255, "CustomerID");
  25. oParam.SourceVersion =
  26. System.Data.DataRowVersion.Original;
  27. mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
  28.  
  29. this.mADO_Adapter.UpdateCommand =
  30. mADO_CommandUpdateDGCustomers;
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. return false;
  36. }
  37. finally
  38. {
  39. oParam = null;
  40. }
  41. return true;
  42.  
4) please note how I used the SourceVersion and SourceColumn to map the
columns's data with the DataSet's Table's structure (ie. column)

5) finally; apply mADO_Adapter.Update (DataSetName, "TableName");
6) if no exception pops up, you've done it! Check for the DB records if
they were updated or not!

From Jason (Kusanagihk)


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2398
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
1
2980
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The...
1
1702
by: Mike Hnatt | last post by:
I'm baffled. My data store (database) is not updating with a refreshed dataset. Here's what is going on: 1) Create a dataset from a table in a database. 2) Create a copy of this dataset and...
3
2185
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I...
4
2245
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
4
2127
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft...
2
2308
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling...
9
3548
by: Michael | last post by:
Hi, I have a large table. Normally, the user will need to see only the data from the past two years, but sometimes, they will need to go back further. I have a form with a datagrid, a...
3
1782
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
1
2279
by: geeteshss | last post by:
Dear all, actually i spent a whole month on the R&D of datagrid edit ,update,cancel events but recently my guide told me to make it user friendly because no user would like to go on searching rows...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
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
7192
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...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.