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. How to convert SqlDataReader into a user defined class?

How to convert SqlDataReader into a user defined class?

Scheduled Pinned Locked Moved C#
databasedata-structurestutorialquestion
5 Posts 2 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.
  • H Offline
    H Offline
    hogan smith
    wrote on last edited by
    #1

    Hi All, Can I covert the SqlDataReader into a user defined class? I will explain my doubt. I have a user defined class named 'Member' which contains the fields same as in the 'Member' table in database. Now I want to select the Members from database and converted to the array of class 'Member'. Is it possible? Is it will causes to overkill? Regards, Hogan

    A 1 Reply Last reply
    0
    • H hogan smith

      Hi All, Can I covert the SqlDataReader into a user defined class? I will explain my doubt. I have a user defined class named 'Member' which contains the fields same as in the 'Member' table in database. Now I want to select the Members from database and converted to the array of class 'Member'. Is it possible? Is it will causes to overkill? Regards, Hogan

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      You can create a method that received as a parameter an SqlDataReader object, and returns a Member array. There for each row in the database you create a new Member object, read the values and at the end return the array. Hope it helps.

      There are 10 kinds of people: those who understand binary and those who don't

      H 1 Reply Last reply
      0
      • A Andrei Ungureanu

        You can create a method that received as a parameter an SqlDataReader object, and returns a Member array. There for each row in the database you create a new Member object, read the values and at the end return the array. Hope it helps.

        There are 10 kinds of people: those who understand binary and those who don't

        H Offline
        H Offline
        hogan smith
        wrote on last edited by
        #3

        Thank you for reply It require a loop. isn't it? I am worried about the performance. This member class in my business layer. Actually SqlDataReader is enough for the purpose. But I want to make it more slandered form Regards, Hogan

        A 1 Reply Last reply
        0
        • H hogan smith

          Thank you for reply It require a loop. isn't it? I am worried about the performance. This member class in my business layer. Actually SqlDataReader is enough for the purpose. But I want to make it more slandered form Regards, Hogan

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          Yes, you need a loop. I gave you a solution to a problem, though i would rather work with SqlDataReader

          There are 10 kinds of people: those who understand binary and those who don't

          H 1 Reply Last reply
          0
          • A Andrei Ungureanu

            Yes, you need a loop. I gave you a solution to a problem, though i would rather work with SqlDataReader

            There are 10 kinds of people: those who understand binary and those who don't

            H Offline
            H Offline
            hogan smith
            wrote on last edited by
            #5

            Ok understood. Thanks to spend your time with me :-D Regards, Hogan

            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