TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Z Hussain
1.4k
348
16.1k
Base Class to handle basic ADO Steps
Feb 27 2019 3:35 PM
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
//First Method
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;
}
//Second Method
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();
// EmpId = int.Parse(System.Web.HttpContext.Current.Session["EmployeeID"].ToString());
objConn.ConnectionString = ConfigurationManager.ConnectionStrings[
"ConnectionString"
].ConnectionString;
objCmd =
new
SqlCommand();
objCmd.CommandText =
"sp_GetToDoList"
;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Connection = objConn;
}
//Another Method
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
Reply
Answers (
2
)
how to do client credential in identityserver4
in datepicker issue mvc