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 convert datareader data into datatable

how to convert datareader data into datatable

Scheduled Pinned Locked Moved ASP.NET
databasetutorial
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.
  • P Offline
    P Offline
    Pallavi Bhoite
    wrote on last edited by
    #1

    earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.

    pallavi

    G G 2 Replies Last reply
    0
    • P Pallavi Bhoite

      earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.

      pallavi

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      Pallavi, Firstly you have to provide structure to the datatable i.e. column names and datatypes.... Once you have the structure set you can loop through your datareader and add one row at a time to your DataTable. You can provide structure to your datatable even after you have data in your datareader!

      Gautham

      P 1 Reply Last reply
      0
      • G gauthee

        Pallavi, Firstly you have to provide structure to the datatable i.e. column names and datatypes.... Once you have the structure set you can loop through your datareader and add one row at a time to your DataTable. You can provide structure to your datatable even after you have data in your datareader!

        Gautham

        P Offline
        P Offline
        Pallavi Bhoite
        wrote on last edited by
        #3

        thank u gautam . but i have three different querries in switch case . and i am going to bind to datgrid according to selected criteria. so, according to u may i hv to make ready different datatables with the different structures? isnt it there any easy way as-- datatable= (datatable)datareader ; (kidding. but i want it as flexivble as dataset). thank u.

        pallavi

        1 Reply Last reply
        0
        • P Pallavi Bhoite

          earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.

          pallavi

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Why don't you want to use the DataAdapter.Fill method? If you want the data in a DataTable you will be doing the same thing as that method does anyway.

          --- single minded; short sighted; long gone;

          P 1 Reply Last reply
          0
          • G Guffa

            Why don't you want to use the DataAdapter.Fill method? If you want the data in a DataTable you will be doing the same thing as that method does anyway.

            --- single minded; short sighted; long gone;

            P Offline
            P Offline
            Pallavi Bhoite
            wrote on last edited by
            #5

            thank u guffa, though dataadapter.fill(........) uses datareader behind the scene, as per requirement i have to use datareader in my code. :( plz help. thanks in advance

            pallavi

            G 1 Reply Last reply
            0
            • P Pallavi Bhoite

              thank u guffa, though dataadapter.fill(........) uses datareader behind the scene, as per requirement i have to use datareader in my code. :( plz help. thanks in advance

              pallavi

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Pallavi Bhoite wrote:

              as per requirement i have to use datareader

              Ok, then you just have to (more or less) rewrite the Fill method in your own code.

              --- single minded; short sighted; long gone;

              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