problem in creating comman connection class
-
hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }
-
hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }
so what is the error in that ?
-
so what is the error in that ?
i want to know ..what is the use of inheriting a clsConnection?? for instance, in class "public class registrationDal:clsConnection "
-
hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }
There is no need to inherite class in second fine instead of that you have to create one instance of that class and you have to use that one for ex. public class registrationDal { public bool SaveCandidateInfo(string jobTitle) { clsConnection oclsConnection = new clsConnection (); SqlConnection con = oclsConnection.connectionMethod(); try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", con); cmd.CommandType = CommandType.StoredProcedure; } catch {} }
-
There is no need to inherite class in second fine instead of that you have to create one instance of that class and you have to use that one for ex. public class registrationDal { public bool SaveCandidateInfo(string jobTitle) { clsConnection oclsConnection = new clsConnection (); SqlConnection con = oclsConnection.connectionMethod(); try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", con); cmd.CommandType = CommandType.StoredProcedure; } catch {} }
ok thanx ...but could u tell me the use of inheriting the class in this case???
-
ok thanx ...but could u tell me the use of inheriting the class in this case???
hi according to me there is not use to inherit the class over here as per inheritance defination one of the use of inheriatance is to reuse your existance class methods and member