Data merge
-
I have a VB.net standalone application. I want a method of merging a table from the database application with a master database. Replication is not an option. I have tried dumping the table from db1 into a dataset (dataset1), and then the same table from db2 into a dataset (dataset2). Will using the dataset merge method combine the data to enable me to update the master. IE. dataset1.Merge(dataset2) dataset1.acceptchanges dataAdapter1.Update(dataset1, "Table1") It seems that dataset1 gets dataset2's data appended, but the datasource does not update. Please advise a method to do this.
-
I have a VB.net standalone application. I want a method of merging a table from the database application with a master database. Replication is not an option. I have tried dumping the table from db1 into a dataset (dataset1), and then the same table from db2 into a dataset (dataset2). Will using the dataset merge method combine the data to enable me to update the master. IE. dataset1.Merge(dataset2) dataset1.acceptchanges dataAdapter1.Update(dataset1, "Table1") It seems that dataset1 gets dataset2's data appended, but the datasource does not update. Please advise a method to do this.
The datasource is not getting updated becasue you called dataset1.AcceptChanges When AcceptChanges is called all the rows in the dataset are marked as unmodified so when the data adapter assesses which rows to update, insert and delete it finds all rows are unmodified and thus thinks it does not need save them.
-
The datasource is not getting updated becasue you called dataset1.AcceptChanges When AcceptChanges is called all the rows in the dataset are marked as unmodified so when the data adapter assesses which rows to update, insert and delete it finds all rows are unmodified and thus thinks it does not need save them.
OK, Rem'd this line out. To enable some debugging I load the page with 4 data grids. the first data grid with 1st dataset, second with 2nd dataset, third with the merge results and a fourth with any changes to 1st dataset if any. Here's my code: 'Merge data dstMBR.Merge(dstMBR1) 'Get any changes encountered in original dataset dstMBR2 = dstMBR1.GetChanges 'dstMBR.acceptchanges 'Bind merged dataset to datagrid dgrd2.DataSource = dstMBR1 dgrd2.DataBind() 'Bind changes(if any)to datagrid dgrd3.DataSource = dstMBR2 dgrd3.DataBind() 'Update data source dadMBR.Update(dstMBR, "users") 'More checks for modified data If not dstMBR.GetChanges(DataRowState.Modified) Is Nothing Then lblStatus.Text = "Modified" End If If not dstMBR.GetChanges(DataRowState.Added) Is Nothing Then lblStatus.Text = "Add" End If If not dstMBR.GetChanges(DataRowState.Deleted) Is Nothing Then lblStatus.Text = "Del" End If End Sub You'll notice that acceptchanges is remarked out
-
I have a VB.net standalone application. I want a method of merging a table from the database application with a master database. Replication is not an option. I have tried dumping the table from db1 into a dataset (dataset1), and then the same table from db2 into a dataset (dataset2). Will using the dataset merge method combine the data to enable me to update the master. IE. dataset1.Merge(dataset2) dataset1.acceptchanges dataAdapter1.Update(dataset1, "Table1") It seems that dataset1 gets dataset2's data appended, but the datasource does not update. Please advise a method to do this.
From reading the MS Help, it looks like the rows of the merged datasets retain their DataRowState from before the merge, so that the "new" datarows would not show as "Added" they probably are showing "Unchanged" since you haven't changed anything in the rows. Then when the Update is done, nothing is changed in the datasource because all the rows in the merged dataset are "Unchanged."
-
From reading the MS Help, it looks like the rows of the merged datasets retain their DataRowState from before the merge, so that the "new" datarows would not show as "Added" they probably are showing "Unchanged" since you haven't changed anything in the rows. Then when the Update is done, nothing is changed in the datasource because all the rows in the merged dataset are "Unchanged."
Anybody know of a work around?
-
Anybody know of a work around?
Copying the changes/additions from the second dataset into the first dataset and then updating the data source. Fill datasets if dataset2 only has additions to dataset1 ...for each row .....read row in dataset2 .....create new row in dataset1 .....fill new row with row from dataset2 Update datasource if dataset2 contains changes to dataset1 ...for each row .....compare row in dataset1 with row in dataset2 .....If there are changes .......make the changes in dataset1 Update datasource
-
Copying the changes/additions from the second dataset into the first dataset and then updating the data source. Fill datasets if dataset2 only has additions to dataset1 ...for each row .....read row in dataset2 .....create new row in dataset1 .....fill new row with row from dataset2 Update datasource if dataset2 contains changes to dataset1 ...for each row .....compare row in dataset1 with row in dataset2 .....If there are changes .......make the changes in dataset1 Update datasource
Thanks, Seem to have the additions working, but problems with comparing rows. What is the correct syntax for comparing datarows. Do I have to compare the value of each column in the row, or can I compare the row as a whole.
-
Thanks, Seem to have the additions working, but problems with comparing rows. What is the correct syntax for comparing datarows. Do I have to compare the value of each column in the row, or can I compare the row as a whole.