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. class concept

class concept

Scheduled Pinned Locked Moved C#
databasequestion
7 Posts 4 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.
  • Y Offline
    Y Offline
    Yonathan1111
    wrote on last edited by
    #1

    Hallo everybody, I'm doing a sample of project which has a base class and other two or more subclasses of the base class. The base class is directly connected to a database when the time is to run. My questions are the following: 1. Is it necessary to embed the connection properties every-time in the subclasses? 2. The same question, but little confusing for me, here it goes: cmd = new SqlCommand("sql statement", con);// found in one of the subclasses Both cmd and con are instances of the class SqlCommand and SqlConnection respectively. Why is con necessary here? I mean, once a connection is established in a base class and inherited in the subclasses, then why? If I might not be clear enough, please let me know. Thank you

    J L P 3 Replies Last reply
    0
    • Y Yonathan1111

      Hallo everybody, I'm doing a sample of project which has a base class and other two or more subclasses of the base class. The base class is directly connected to a database when the time is to run. My questions are the following: 1. Is it necessary to embed the connection properties every-time in the subclasses? 2. The same question, but little confusing for me, here it goes: cmd = new SqlCommand("sql statement", con);// found in one of the subclasses Both cmd and con are instances of the class SqlCommand and SqlConnection respectively. Why is con necessary here? I mean, once a connection is established in a base class and inherited in the subclasses, then why? If I might not be clear enough, please let me know. Thank you

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Yonathan1111 wrote:

      If I might not be clear enough, please let me know

      Its not clear what your question is. post some code.

      Y 1 Reply Last reply
      0
      • Y Yonathan1111

        Hallo everybody, I'm doing a sample of project which has a base class and other two or more subclasses of the base class. The base class is directly connected to a database when the time is to run. My questions are the following: 1. Is it necessary to embed the connection properties every-time in the subclasses? 2. The same question, but little confusing for me, here it goes: cmd = new SqlCommand("sql statement", con);// found in one of the subclasses Both cmd and con are instances of the class SqlCommand and SqlConnection respectively. Why is con necessary here? I mean, once a connection is established in a base class and inherited in the subclasses, then why? If I might not be clear enough, please let me know. Thank you

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Yonathan1111 wrote:

        1. Is it necessary to embed the connection properties every-time in the subclasses?

        No, you can put the connection data anywhere, as long as the subclass can reach it at run time.

        Yonathan1111 wrote:

        Why is con necessary here?

        The SqlCommand object needs access to the SqlConnection object in order to know which database it is referring to. Your program could be accessing multiple databases.

        It's time for a new signature.

        Y 1 Reply Last reply
        0
        • Y Yonathan1111

          Hallo everybody, I'm doing a sample of project which has a base class and other two or more subclasses of the base class. The base class is directly connected to a database when the time is to run. My questions are the following: 1. Is it necessary to embed the connection properties every-time in the subclasses? 2. The same question, but little confusing for me, here it goes: cmd = new SqlCommand("sql statement", con);// found in one of the subclasses Both cmd and con are instances of the class SqlCommand and SqlConnection respectively. Why is con necessary here? I mean, once a connection is established in a base class and inherited in the subclasses, then why? If I might not be clear enough, please let me know. Thank you

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          The Connection and Command should be embedded in a separate Data Access Layer class, which the others all use as necessary.

          Y 1 Reply Last reply
          0
          • J J4amieC

            Yonathan1111 wrote:

            If I might not be clear enough, please let me know

            Its not clear what your question is. post some code.

            Y Offline
            Y Offline
            Yonathan1111
            wrote on last edited by
            #5

            Thank you for your cooperation. I don't have code sample, it is a design. I'm asking what logic should I follow? Thanks

            1 Reply Last reply
            0
            • L Lost User

              Yonathan1111 wrote:

              1. Is it necessary to embed the connection properties every-time in the subclasses?

              No, you can put the connection data anywhere, as long as the subclass can reach it at run time.

              Yonathan1111 wrote:

              Why is con necessary here?

              The SqlCommand object needs access to the SqlConnection object in order to know which database it is referring to. Your program could be accessing multiple databases.

              It's time for a new signature.

              Y Offline
              Y Offline
              Yonathan1111
              wrote on last edited by
              #6

              Thank you You gave me a hint. Thanks

              1 Reply Last reply
              0
              • P PIEBALDconsult

                The Connection and Command should be embedded in a separate Data Access Layer class, which the others all use as necessary.

                Y Offline
                Y Offline
                Yonathan1111
                wrote on last edited by
                #7

                Thank you very much, that is what I want. Thnks

                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