473,320 Members | 1,978 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,320 software developers and data experts.

Dataset Merge

Here's my question..

I have a Dataset which has populated a datagrid with information from an AS400
That SQL looks like this
"Select MASYS, MAFLD, MADATA, MAEQV from QS36F.MAPDATA WHERE MASYS = ? AND MAFLD = ?
It populates a data adapter in which at that point I open a new dataset and I have the parameters and such setup including the proper update, insert and delete commands created as well. It works great
I can update and insert and all that wonderful stuff
Here's the problem..
I have another dataset which I open to when the user clicks on a button called "Build"
That SQL looks like this

"Select distinct 'EL0' as MASYS, 'CBMAK' as MAFLD, cbmak as MADATA, '' as MAEQV from qs36f.cgibase where cbmak not in (select madata from qs36f.mapdata where masys = 'EL0' and mafld = 'CBMAK')

The purpose of this "build" button is to grab a bunch of values that will be merged with the existing dataset
Consider this example...
You have a coat rack with 10 coats on it....5 of the coats have people who own them and the other five do not
The five who do have owners are currently populated into the datagrid with their owners names beside them. The other 5 however are not in the datagrid. The build button grabs the 5 coats without owners and merges that info into the existing dataset so that the user can add the names to the coats without names.
Here's the problem...the following lin

myconnection.getDataSet(datasetkey).Merge(myconnec tion.getDataSet(dsKey), True, MissingSchemaAction.AddWithKey

(getdataset retrieves a currently open dataset distinguished from another by a variable "datasetkey" or "dsKey". Both are just a random number integer value to keep track of open datasets

This line adds the newly opened dataset information to the datagrid and seems to add it to the original datagrid, however, when I try to modify information that has been merged I get this error on the update

An unhandled exception of type 'System.Data.DBConcurrencyException' occurred in system.data.dl
Additional information: Concurrency violation: the UpdateCommand affected 0 records

The update code looks like this..

Dim adapter As System.Data.Odbc.OdbcDataAdapter = myconnection.getAdapter(datasetkey
adapter.Update(CType(MyDataGrid.DataSource, System.Data.DataSet)

It crashes on the second line. When I try refreshing the original Dataset....the merged information is not there

Why does it merge the second datasets info to the datagrid but doesn't seem like it's being merged into the orginal dataset

Thank
Jul 21 '05 #1
4 4420
Upon further inspection of this problem I have figured out that when I merged the two datasets together....when I do the dataadapter update it thinks that because it's now apart of the orginal dataset that the record exists in the DB...so it calls the "update" command instead of the "insert" command. This is a big problem. Suffice to say it's a little difficult to update a record in the DB that doesn't exist.

Does anyone know how to go bout fixing this little problem

Thanks
Jul 21 '05 #2
Hi,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that after you called DataSet.Merge method,
you would like to insert the rows that were added to the taget DataSet to
the source database by
calling Update method. If there is any misunderstanding, please feel
free to let me know.

DataSet.Merge method merges data from other data source. The source can be
an array of DataRows, a DataTable or a DataSet. However, after merging, the
RowState property of rows that were imported from the source will not be
changed to Added. They remains to be Unchanged. As Update method recognize
the newly added rows by checking it's RowState property, they cannot be
figured out.

So if you would like to get the rows from other DataSet
and update the database, it is recommended to detach the rows from other
DataSets and add them to the DataRowCollection using
DataSet.Table["tabname"].Rows.Add(OriginalRow.ItemArray). The
DataRow.ItemArray property will return the field values of a row.

For more information about DataSet.Merge and DataRowCollection.Add method,
please check the following links for reference:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemDataDataSetClassMergeTopic.asp

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemDataDataRowCollectionClassAddTopic.asp

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
Hey Kevin

First off thanks for the reply

Your understanding of my problem was right on. You also explained how exactly the dataset.merge works in regards to updating after a merge. I looked many places for this information but came up short. Your solution to this problem worked great thank you for your help
My solution was to get the row with the error...in this case any row that was merged to the original Dataset and add an event handler that would allow me to do a manual insert on the rows that failed. I would then refresh the data.
Your way seems far more logical

Thanks again!
Jul 21 '05 #4
You're welcome. Thanks for sharing your experience with everyone in the
community. If you have any questions, please feel free to post in the
community. We will try our best to help you.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5

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

Similar topics

8
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
3
by: Li Weng | last post by:
Hi, I have an original dataset. It is copied to 2 different forms. Each form adds a new row to the same table in that dataset. When I merge these 2 dataset back to original one, the 2 new rows...
2
by: Mike Stephens | last post by:
A contact management application we previously developed for a customer now has a requirement to perform mail merging. Normally request like this would be very simple to solve, we were just point...
2
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge(...
4
by: Al | last post by:
I have this scenario: 1. XML file with schema and data is created from SQL Server tables. XML file contains 6 tables, some of them have rows, some of them are empty. 2. XML file is given to the...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
5
by: Mark Chambers | last post by:
Hi there, Can anyone explain the following (very) simple scenario. 1) I make an exact copy of my "DataSet" and delete one record from a given table (in the copy) 2) I invoke...
5
by: Franck | last post by:
how come unchanged always true even if data changed This code come from my saving button: ============================================ DataSet ds1 = new DataSet(); DataSet ds2 = new...
2
by: Neil Chambers | last post by:
I am trying to get my head around dataset merging but despite a little research I could still use a pointer (or ten). Basically I want to perform an outer join operation on a dataset (created from...
1
by: joproulx | last post by:
Hello all, Here is my problem: I am trying to merge 2 datasets but I don't want to overwrite rows that are already modified in my working dataset. Example: I have one Dataset with only one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.