Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Data merge

Data merge

Scheduled Pinned Locked Moved Database
csharpdatabaseannouncement
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pedros73 0
    wrote on last edited by
    #1

    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.

    P N 2 Replies Last reply
    0
    • P pedros73 0

      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.

      P Offline
      P Offline
      pjholliday
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • P pjholliday

        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.

        P Offline
        P Offline
        pedros73 0
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • P pedros73 0

          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.

          N Offline
          N Offline
          numbrel
          wrote on last edited by
          #4

          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."

          P 1 Reply Last reply
          0
          • N numbrel

            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."

            P Offline
            P Offline
            pedros73 0
            wrote on last edited by
            #5

            Anybody know of a work around?

            N 1 Reply Last reply
            0
            • P pedros73 0

              Anybody know of a work around?

              N Offline
              N Offline
              numbrel
              wrote on last edited by
              #6

              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

              P 1 Reply Last reply
              0
              • N numbrel

                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

                P Offline
                P Offline
                pedros73 0
                wrote on last edited by
                #7

                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.

                N 1 Reply Last reply
                0
                • P pedros73 0

                  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.

                  N Offline
                  N Offline
                  numbrel
                  wrote on last edited by
                  #8

                  I'm just learning all this myself and I would have to compare each column in the rows. Maybe someone else knows of a compare method. A new thread with that question as the topic might get more notice, either here or under the language you are using.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups