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. Datatable Merge IN C#.Net

Datatable Merge IN C#.Net

Scheduled Pinned Locked Moved Database
databasecsharpsql-servercomsysadmin
4 Posts 2 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.
  • A Offline
    A Offline
    adnanrafiq
    wrote on last edited by
    #1

    Hi All, I have two datatables, one datatable named "dtRecords1" gets filled from excel sheet, having column name "Name","Category", and on run time i have added a Identity column to "dtRecords1". Second Column gets filled from sql server database having three columsn "ID as Identity","Name","Category". Now i want to merge these two tables, i want this result from merge. If there are some changes in first datatable, depending upon all columns (comparing all column values) and ID Is same,it should be overwrited, and if there are some new rows these also should be added to the resulted database. Example: Datatable1 from excel ID,Name,Categoey 1,adnan,SE 2,ali,SSE 3,Imran,JSE Datatable2 From SQL Server DB ID,Name,Category 1,adnan,SSE 2,ali,SSE Resulted Datatable ID,Name,Category 1,adnan,SE -Changed ROw 2,ali,SSE -Unchanged Row 3,Imran,JSE - Newly added Row Many THanks & Best Regards, adnan

    Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com

    S 1 Reply Last reply
    0
    • A adnanrafiq

      Hi All, I have two datatables, one datatable named "dtRecords1" gets filled from excel sheet, having column name "Name","Category", and on run time i have added a Identity column to "dtRecords1". Second Column gets filled from sql server database having three columsn "ID as Identity","Name","Category". Now i want to merge these two tables, i want this result from merge. If there are some changes in first datatable, depending upon all columns (comparing all column values) and ID Is same,it should be overwrited, and if there are some new rows these also should be added to the resulted database. Example: Datatable1 from excel ID,Name,Categoey 1,adnan,SE 2,ali,SSE 3,Imran,JSE Datatable2 From SQL Server DB ID,Name,Category 1,adnan,SSE 2,ali,SSE Resulted Datatable ID,Name,Category 1,adnan,SE -Changed ROw 2,ali,SSE -Unchanged Row 3,Imran,JSE - Newly added Row Many THanks & Best Regards, adnan

      Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      I don't think there is a merge method in the DataTable class, there is in DataSet though if all else fails. I'm sure you could use importrow though like so:

      for (int x = 0; x < datatable2.Rows.Count; x++)
      {
      datatable1.ImportRow(datatable2.Rows[x])
      }

      There are 10 types of people in the world, those who understand binary and those who dont.

      A 1 Reply Last reply
      0
      • S ScottM1

        I don't think there is a merge method in the DataTable class, there is in DataSet though if all else fails. I'm sure you could use importrow though like so:

        for (int x = 0; x < datatable2.Rows.Count; x++)
        {
        datatable1.ImportRow(datatable2.Rows[x])
        }

        There are 10 types of people in the world, those who understand binary and those who dont.

        A Offline
        A Offline
        adnanrafiq
        wrote on last edited by
        #3

        I am 100% sure there is method merge in datatable, when i create instance of datatable, press dot, you will also see, merge method. Will you please help to fullfill the requirment that i have asked in question or explain what you have in this loop. Many Thanks, adnna

        Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com

        S 1 Reply Last reply
        0
        • A adnanrafiq

          I am 100% sure there is method merge in datatable, when i create instance of datatable, press dot, you will also see, merge method. Will you please help to fullfill the requirment that i have asked in question or explain what you have in this loop. Many Thanks, adnna

          Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          Sorry, I didn't check. Google datatable.merge

          There are 10 types of people in the world, those who understand binary and those who dont.

          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