By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Dataset Merge

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.