A brief talk on variable reference and transfer in ASP.net multilayer architecture

Source: Internet
Author: User

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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.