I am trying to open a connection to a database and I have used a configuration string to connect and I've instantiated the sqlConnection object. I would like to be able to use this reference in a new classes method. Why am I not able to achieve this? Why does it say "this class cannot be inherited"?
namespace sqlLibrary
{
public class sqlStuff
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SurplusConnectionString"].ConnectionString);
}
public class commands : sqlStuff
{
public void executeQuery()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection; --> Not able to get reference from sql stuff class?
}
}
}