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
  1. Home
  2. General Programming
  3. C#
  4. Copy values in column to another column

Copy values in column to another column

Scheduled Pinned Locked Moved C#
tutorial
3 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.
  • S Offline
    S Offline
    shoubi
    wrote on last edited by
    #1

    Hi all how to transfer values from one datatable to another datatable. For example there are 2 datatables Table A and Table B. If then column name in Table A is the same as Table B then all the values of that column will go into Table B of the same column name. Hope you understand me. Thank you zheng

    M Y 2 Replies Last reply
    0
    • S shoubi

      Hi all how to transfer values from one datatable to another datatable. For example there are 2 datatables Table A and Table B. If then column name in Table A is the same as Table B then all the values of that column will go into Table B of the same column name. Hope you understand me. Thank you zheng

      M Offline
      M Offline
      MayukhSen
      wrote on last edited by
      #2

      For Each dr As DataRow In sourceTable.Rows
      destinationTable.ImportRow(dr)
      Next

      sourceTable is Table A destinationTable is Table B

      1 Reply Last reply
      0
      • S shoubi

        Hi all how to transfer values from one datatable to another datatable. For example there are 2 datatables Table A and Table B. If then column name in Table A is the same as Table B then all the values of that column will go into Table B of the same column name. Hope you understand me. Thank you zheng

        Y Offline
        Y Offline
        yu jian
        wrote on last edited by
        #3

        If you want to add a new column from table A to table B you should foreach the data row of the table a

                   DataTable b, a;
                    foreach (DataRow dr in a.Rows)
                    {
                        string id = dr["id"].ToString(); /// "id" is the primary key
                        DataRow[] bDr = b.Select(string.Format("id = '{0}'", id));
                        bDr[0]["value"] = dr["value"];   // value is the new column you want to add
                    }
        
        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