Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Inheriting members of a class

I have a class with the following attribute

      public class customers : System.Web.UI.Page
{

protected System.Data.SqlClient.SqlConnection customer_connection;
}

How can I build or inherit a new instance of customer_connection, in this class? Both classes exist in the same namespace.

      "public class orders : System.Web.UI.Page"

Thanks,
Sean
0
sean-keys
Asked:
sean-keys
  • 2
1 Solution
 
BurntSkyCommented:
It seems like you're asking two different things, neither of which are very clear, but I'll give it a shot.

If you want to instantiate customer_connection from within an instance of the "customers" class you can simply use this:

private void MyMethod()
{
   this.customer_connection = new SqlConnection();
}

if you want to inherit it in a derived class and instantiate it from there you can do this:

public class MyDerivedClass : customers
{
   private void MyMethod()
   {
      this.customer_connection = new SqlConnection();
   }
}

customer_connection is visible to MyDerivedClass because it directly inherits from "customers" which provides the member as "protected"

I'm not sure what the "orders" class is all about.  Perhaps you could clarify your question if I didn't answer it here.
0
 
sean-keysAuthor Commented:
I'm trying to use the SqlConnection (customer_connection) on another webform, but I'm not sure what the best way to do it is.

0
 
BurntSkyCommented:
You're trying to use it on another page that does not inherit from "customers"?  You can't do that.  But what you can do is put the SqlConnection in another class and access it statically.

public class DataAccess
{
   public static SqlConnection Customer_Connection;
}

and then you can access it from any other class.  This really isn't the preferred method but unless you're developing an extensive enterprise application it doesn't really matter.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now