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. select specific column from datatable

select specific column from datatable

Scheduled Pinned Locked Moved ASP.NET
database
5 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
    playout
    wrote on last edited by
    #1

    Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.

    K N 2 Replies Last reply
    0
    • P playout

      Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben

      P N 2 Replies Last reply
      0
      • K kubben

        I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben

        P Offline
        P Offline
        playout
        wrote on last edited by
        #3

        Thank you Ben, I think this method will help me a lot. Will try it over the weekend. Regards Playout

        1 Reply Last reply
        0
        • K kubben

          I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Provided of course that the ordinal of the columns doesn't change. This is a bit brute force and not really necessary.


          only two letters away from being an asset

          1 Reply Last reply
          0
          • P playout

            Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            First way would be to have the database query return only the column you are looking for. Otherwise try this DataTable EmployeeName = new DataTable(); EmployeeName.Columns.Add("EmployeeName"); EmployeeName.Merge(fullDataTable);


            only two letters away from being an asset

            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