473,757 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ge tDataSet(datase tkey).Merge(myc onnection.getDa taSet(dsKey), True, MissingSchemaAc tion.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.DB ConcurrencyExce ption' 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.Odb c.OdbcDataAdapt er = myconnection.ge tAdapter(datase tkey
adapter.Update( CType(MyDataGri d.DataSource, System.Data.Dat aSet)

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 4447
Upon further inspection of this problem I have figured out that when I merged the two datasets together....whe n 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 misunderstandin g, 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 DataRowCollecti on using
DataSet.Table["tabname"].Rows.Add(Origi nalRow.ItemArra y). The
DataRow.ItemArr ay property will return the field values of a row.

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

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemData DataSetClassMer geTopic.asp

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemData DataRowCollecti onClassAddTopic .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
749
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 Datatable. No coding by programer, All wizardry. User starts app, opens form, adds (4) records and clicks update.
3
1657
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 merge to one! My question is how I can still keep them as 2 rows in that table, not merge to one? Thanks. Li
2
4295
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 the mail merge data source to the database. But this request is a little bit different. The customer needs to perform the mail merge from the contacts in a dataset. Example In the main contact window the client has the ability to filter contact...
2
2110
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( myCustomDataSet.MyTable, bPreserveChanges, MissingSchemaAction.Add ); ds.AcceptChanges(); // tried with and without this line
4
2253
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 person with Pocket PC. 3. XML file is used to populate DataSet on the Pocket PC. 4. User adds new rows, changes values, deletes some rows. 5. Altered dataset is saved back to XML file. 6. XML file is given back to the person who initially created...
1
2539
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 can re-run the report and get fresh data. now, they would like to be able to compare the fresh data to the stored data, getting a break-down of added/deleted/changed rows. on the surface, this sounded plausible -- by deserializing the stored
5
16705
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 "DataSet.GetChanges()" on the above copy and pass the results to "DataSet.Merge()" on the original copy 3) If I now inspect the original copy, it shows that the record has *not* been deleted from the table. However, a call to "GetChanges()" does show my
5
1861
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 DataSet(); DataSet ds3 = new DataSet(); //Static Dataset which contain values when my form load
2
1858
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 a file operation) and the resulting sql query based on the contents of said dataset. Effectively I would end up with two dataset tables in my application. If I were writing this to action from two tables it would be thus: SELECT ds.id, db.*
1
6196
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 DataTable in it. The DataTable has these 2 columns: Column #1: Name="Id" Type=Int32 (Primary Key)
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7285
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
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 we have to send another system
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.