Recently more leisurely, just use this time to carefully study the ASP.net multi-layer structure, the main reference is the Wrox of a <.net WebSite programming problem-design-solution> Personally think this book is good. For developers with a certain. NET base, it may seem difficult to understand at first, but a closer look at this book is an excellent reference manual for engineering applications.
ASP.net's multi-layer architecture is mainly to solve the relationship between data layer, logic layer, presentation layer and so on. My approach is this: first, create a DataCore base class. The base class encapsulates the basic operations of some low-level databases, such as database joins, calling stored procedures, and so on. There's a place in here. It is noteworthy that a stored procedure that invokes different functions can be implemented by overloading a function. The following code example:
protected int Runprocedure (string storedprocname, idataparameter[] parameters, out int rowsaffected)
{
int result;
Connection.Open ();
SqlCommand command = Buildintcommand (storedprocname, parameters);
rowsaffected = command. ExecuteNonQuery ();
result = (int) command. parameters["ReturnValue"]. Value;
Connection.close ();
return result;
}
Protected SqlDataReader runprocedure (String storedprocname, idataparameter[] parameters)
{
SqlDataReader Returnreader;
Connection.Open ();
SqlCommand command = Buildquerycommand (storedprocname, parameters);
Command.commandtype = CommandType.StoredProcedure;
Returnreader = command. ExecuteReader ();
Connection.close ();
return returnreader;
}
Protected DataSet runprocedure (String storedprocname, idataparameter[] parameters, string tablename)
{
DataSet DataSet = new DataSet ();
Connection.Open ();
SqlDataAdapter SqlDA = new SqlDataAdapter ();
Sqlda.selectcommand = Buildquerycommand (storedprocname, parameters);
Sqlda.fill (DataSet, TableName);
Connection.close ();
return dataSet;
}
protected void Runprocedure (String storedprocname, idataparameter[] Parameters, DataSet DataSet, string tablename)
{
Connection.Open ();
SqlDataAdapter SqlDA = new SqlDataAdapter ();
Sqlda.selectcommand = Buildintcommand (storedprocname, parameters);
Sqlda.fill (DataSet, TableName);
Connection.close ();
}