class concept
-
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
-
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
-
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
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 theSqlConnection
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.
-
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
The Connection and Command should be embedded in a separate Data Access Layer class, which the others all use as necessary.
-
Yonathan1111 wrote:
If I might not be clear enough, please let me know
Its not clear what your question is. post some code.
Thank you for your cooperation. I don't have code sample, it is a design. I'm asking what logic should I follow? Thanks
-
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 theSqlConnection
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.
Thank you You gave me a hint. Thanks
-
The Connection and Command should be embedded in a separate Data Access Layer class, which the others all use as necessary.
Thank you very much, that is what I want. Thnks