Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging Datasets

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
I'm not sure that I understand the Merge method correctly. I have two datasets each with its own datadapter.

The first:
DataAdapter --> daAccess 'generates a dataset from an access dbase
Dataset --> DsBillingRatesAccess1

The second:
DataAdapter --> daSQL 'generates a dataset from an SQL dbase
Dataset --> DsBillingRatesSQL1

I have a form with two datagrids on it, dgAccess and dgSQL.

The datagrid on the left is bound to DsBillingRatesAccess1 and the datagrid on the right is bound to DsBillingRatesSQL1. I load the Access data into dgAccess when a button is pressed. I have another button that I use to Merge the data in DsBillingRatesAccess1 into DsBillingRatesSQL1 (which is empty to start with). Here is the code for the merge button.
Code:
DsBillingRatesSQL1.Merge(DsBillingRatesAccess1, False)
I expect that when the merge button is pressed that the datagrid on the right will fill up with the merged data, but it doesn't. Once the datagrid on the right is filled up I want to call the Update method on the daSQL datadapter to persist changes to the SQL database.

Is there something else I need to do after I merge the source dataset into the target dataset in order for the datagrid on the right to fill up with the data? Does it have something to do with each of the separate datasets being typed differently?

 
Thanks,

Now I have the datasets merging, but now I can't seem to commit the changes from the merge back to the database.

I have a button that I want to click and update the database with the rows added to the table in DsSqlBillingRates1 during the merge. Here is the code I am using to do that.
Code:
Dim AddedRecords As DataTable = _
     DsSqlBillingRates1.tbl_Billing_Rate.GetChanges(DataRowState.Added)

Try
     daSql.Update(AddedRecords)
Catch ex As Exception
     If AddedRecords Is Nothing Then
          System.Windows.Forms.MessageBox.Show("The " & _
          "datatable you are trying to use to perform is empty.")
     End If
End Try
When I merge the two datasets, the previously empty dataset shows the new records in it's datagrid, but when I call the update method on the DataAdapter, the AddedRecords table always turns up empty. But I can see the new records in the datagrid. What's wrong?
 
Okay, now I see that the reason the datatable is empty is because I am getting the DataRowState.Added rows. I see now that whenever the merge is performed, the rows aren't marked as DataRowState.Added, but as DataRowState.Unchanged.

So here's the deal. There are two datasets. The first one contains records. The second one is empty until the data from the first is merged with it. Is there any way, during the merge, for the rows to be marked as DataRowState.Added so that I may call the Update method on the second dataset's DataAdapter and persist changes to the database?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top