How to creat a base class or utility that handles the basics of creating a connection, command, parameters, etc. so that I don’t have that code in each method or class reduces chances for errors and simplifies updates?
Example: I have many Methods and I'm sure there'z a way to create a base class by atleast creating a Constructor or creating and inheriting base class
-
- public void InsertToDoList(ToDoListProp ToDoListProp)
- {
- SqlConnection objConn = new SqlConnection();
- SqlCommand objCmd = new SqlCommand();
- SqlDataAdapter objDa = new SqlDataAdapter();
- DataSet objDs = new DataSet();
-
-
- objConn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
- objCmd = new SqlCommand();
- objCmd.CommandText = "sp_WebToDoListSet";
- objCmd.CommandType = CommandType.StoredProcedure;
- objCmd.Connection = objConn;
- }
-
-
- public DataSet GetToDoList(int EmployeeId)
- {
- List<ProjectProp> ProjectList;
- ProjectList = new List<ProjectProp>();
-
-
- SqlConnection objConn = new SqlConnection();
- SqlCommand objCmd = new SqlCommand();
- SqlDataAdapter objDa = new SqlDataAdapter();
- DataSet objDs = new DataSet();
-
-
-
- objConn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
- objCmd = new SqlCommand();
- objCmd.CommandText = "sp_GetToDoList";
- objCmd.CommandType = CommandType.StoredProcedure;
- objCmd.Connection = objConn;
- }
-
-
- public void DeleteToDoList(int ToDoListId)
- {
- SqlConnection objConn = new SqlConnection();
- SqlCommand objCmd = new SqlCommand();
- SqlDataAdapter objDa = new SqlDataAdapter();
- DataSet objDs = new DataSet();
-
- objConn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
- objCmd = new SqlCommand();
- objCmd.CommandText = "sp_DeleteToDoList";
- objCmd.CommandType = CommandType.StoredProcedure;
- objCmd.Connection = objConn;
- }
Any Help will be much appreciated!
Thanks