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. Web Development
  3. ASP.NET
  4. How to Import columns from one datatable to another

How to Import columns from one datatable to another

Scheduled Pinned Locked Moved ASP.NET
csharpquestionlinqhelptutorial
4 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.
  • M Offline
    M Offline
    meeram395
    wrote on last edited by
    #1

    I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,

    Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

    R T 2 Replies Last reply
    0
    • M meeram395

      I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,

      Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

      R Offline
      R Offline
      Rhys Gravell
      wrote on last edited by
      #2

      OK, I'll bite, why do you need it in a new DataTable?

      Rhys "I'd rather die on my feet than live on my knees"

      M 1 Reply Last reply
      0
      • M meeram395

        I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,

        Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

        T Offline
        T Offline
        thatraja
        wrote on last edited by
        #3

        meeram395 wrote:

        Looping trhough row is not possible.

        Here is one way[^] DataTable.ReadXmlSchema Method[^]

        thatraja |Chennai|India|


        Brainbench certifications
        Down-votes are like kid's kisses don't reject it :-)
        Do what you want quickly because the Doomsday on 2012 :-)

        1 Reply Last reply
        0
        • R Rhys Gravell

          OK, I'll bite, why do you need it in a new DataTable?

          Rhys "I'd rather die on my feet than live on my knees"

          M Offline
          M Offline
          meeram395
          wrote on last edited by
          #4

          Why because, the requirement is that, the column name should be the name from the database which user entered through UI (User friendly column Names). And one column will be mapped to multiple columns, means column A in datatable 1 will be named as 'TestColumn1' and 'TestColumn2' even though the column values are exactly same. Also, only require 3 or 4 columns out of 8 or 10. So I can keep the existing table intact and copy only the required columns to new datatable and change the name.

          Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

          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