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. insert row into a datatable from other datatable at some particular position

insert row into a datatable from other datatable at some particular position

Scheduled Pinned Locked Moved C#
databasexmlhelpquestion
6 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
    S Aijaz
    wrote on last edited by
    #1

    i have table 1 and table 2, both have same schema. i want to insert rows from tabel2 into table1 at some particular position say position 3. how can i do it. with import row it inserts row at the end of the table so it cant help me.

    H 1 Reply Last reply
    0
    • S S Aijaz

      i have table 1 and table 2, both have same schema. i want to insert rows from tabel2 into table1 at some particular position say position 3. how can i do it. with import row it inserts row at the end of the table so it cant help me.

      H Offline
      H Offline
      Hum Dum
      wrote on last edited by
      #2

      You have to create a third table. And insert in it as you want

      S 1 Reply Last reply
      0
      • H Hum Dum

        You have to create a third table. And insert in it as you want

        S Offline
        S Offline
        S Aijaz
        wrote on last edited by
        #3

        how is it possible can u please write some lines of code if possible. i tell you what i want is i want ROW1 from table 1, ROW2 from table 2, ROW3 from table 1 etc. i tried to use insert at and the issue it throw is row belongs to other table.

        H D 2 Replies Last reply
        0
        • S S Aijaz

          how is it possible can u please write some lines of code if possible. i tell you what i want is i want ROW1 from table 1, ROW2 from table 2, ROW3 from table 1 etc. i tried to use insert at and the issue it throw is row belongs to other table.

          H Offline
          H Offline
          Hum Dum
          wrote on last edited by
          #4

          Select rows you want from table1 insert it into 3rd table. Same for table2. Then you have table3 with rows you want. If you want them in ordered way then you must have unique key on which you can sort table.

          1 Reply Last reply
          0
          • S S Aijaz

            how is it possible can u please write some lines of code if possible. i tell you what i want is i want ROW1 from table 1, ROW2 from table 2, ROW3 from table 1 etc. i tried to use insert at and the issue it throw is row belongs to other table.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You cannot copy DataRow objects from one DataTable to another unless they have the EXACT same schema. Your better option would be to create a new DataRow in the target table and copy the values you want from the source table.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            S 1 Reply Last reply
            0
            • D Dave Kreskowiak

              You cannot copy DataRow objects from one DataTable to another unless they have the EXACT same schema. Your better option would be to create a new DataRow in the target table and copy the values you want from the source table.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              S Offline
              S Offline
              S Aijaz
              wrote on last edited by
              #6

              i did it with creating row instance for both the tables (table1 and Table 2) and then set Table1Row.ItemArray = Table2Row.ItemArray; and then added the row to table one at desired location. it worked fine....... thanx for your replies it was of grt help

              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