473,378 Members | 1,492 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,378 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 4424
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.