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. .NET (Core and Framework)
  4. Question on DataReader Class

Question on DataReader Class

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharptutorial
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.
  • H Offline
    H Offline
    harshGupta
    wrote on last edited by
    #1

    Hello, This is my first message here, so my Hello to you all again!!:) This question is not quite related to coding, not directly atleast. I am just curious to know how DataReader class in .Net works?? Scenario is: We do not call the constructor of DataReader class, this means that its constructor is marked "Private". Rather we use a Method, "ExecuteReader" of another Class "Command" while creating DataReader's object. I am trying to mimic this thing. I can do this easily if ExecuteReader method belongs to the same class i.e. DataReader, but I have no idea how to implement the same technique using 2 seperate classes. Command.ExecuteReader method returns a DataReader object, but does it also calls its constructor? Inheriting DataReader Class is not possible because it is also marked "Sealed", so how can I implement the same thing?? Thank you. Hope I have put the question well!! :rolleyes: --- HARSH GUPTA

    G 1 Reply Last reply
    0
    • H harshGupta

      Hello, This is my first message here, so my Hello to you all again!!:) This question is not quite related to coding, not directly atleast. I am just curious to know how DataReader class in .Net works?? Scenario is: We do not call the constructor of DataReader class, this means that its constructor is marked "Private". Rather we use a Method, "ExecuteReader" of another Class "Command" while creating DataReader's object. I am trying to mimic this thing. I can do this easily if ExecuteReader method belongs to the same class i.e. DataReader, but I have no idea how to implement the same technique using 2 seperate classes. Command.ExecuteReader method returns a DataReader object, but does it also calls its constructor? Inheriting DataReader Class is not possible because it is also marked "Sealed", so how can I implement the same thing?? Thank you. Hope I have put the question well!! :rolleyes: --- HARSH GUPTA

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

      You can make the constructor internal, that means that any class in the same assembly can use it.

      --- b { font-weight: normal; }

      H 1 Reply Last reply
      0
      • G Guffa

        You can make the constructor internal, that means that any class in the same assembly can use it.

        --- b { font-weight: normal; }

        H Offline
        H Offline
        harshGupta
        wrote on last edited by
        #3

        If I make it internal, then I could even call it's constructor from Main method(in C#) or New Sub (in VB), which I am trying to avoid!!

        R G 2 Replies Last reply
        0
        • H harshGupta

          If I make it internal, then I could even call it's constructor from Main method(in C#) or New Sub (in VB), which I am trying to avoid!!

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Hi, it all depends on how you dstribute your classes onto your assemblies. If your main method is within the same assembly than it could surel create an instance. You should think if it would be better to separate your main method from other classes. Fact is that the different IDataReader implementations in the .Net framework all have internal constructors. Thus any class in the System.Data assembly could instantiate them. Robert

          H 1 Reply Last reply
          0
          • H harshGupta

            If I make it internal, then I could even call it's constructor from Main method(in C#) or New Sub (in VB), which I am trying to avoid!!

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

            hgupta1983 wrote:

            If I make it internal, then I could even call it's constructor from Main method(in C#) or New Sub (in VB), which I am trying to avoid!!

            Then don't put it in the same assembly as the main program.

            --- b { font-weight: normal; }

            1 Reply Last reply
            0
            • R Robert Rohde

              Hi, it all depends on how you dstribute your classes onto your assemblies. If your main method is within the same assembly than it could surel create an instance. You should think if it would be better to separate your main method from other classes. Fact is that the different IDataReader implementations in the .Net framework all have internal constructors. Thus any class in the System.Data assembly could instantiate them. Robert

              H Offline
              H Offline
              harshGupta
              wrote on last edited by
              #6

              Thank you Robert and Guffa. So Assembly is the key in this scenario. Got it working. --- Harsh Gupta

              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