Use of Asp.net sqlhelper data access layer

Source: Internet
Author: User

Ben ArticleThis section describes how to use sqlhelper.
Each project uses the data access layer, which is no exception. However, when I make the data access layer an independent project, there is no big purpose, it is only used for data access and does not contain any logic.

Why use the data access layer?
If you do not use the data access layerCodeThere will be a lot of sqlconnection, sqlcommand, sqldatareader, open, close ...... These classes and methods, and the large amount of code, leave you bored, and the code writing is actually all physical, no technical content. Therefore, we need to encapsulate the data access layer to facilitate reuse. Microsoft has done this for us, that is, sqlhelper, which is the class Relation Diagram of sqlhelper:

The following describes how to use it.

Execute a stored procedure without return values:
Create proc p_delete @ ID int
As
Delete Table1 where id = @ ID

This is a stored procedure for data deletion. To call this stored procedure, you only need one sentence: sqlhelper. executenonquery (sqlhelper. conn, "p_delete", ID);, the ID here is the int type, not the sqlparameter type. This call is the called public static int executenonquery (string connectionstring, string spname, Params object [] parametervalues) method. And so on. Returns a dataset type: sqlhelper. executedataset (sqlhelper. Conn, Pro, parameter list). parameters are also directly transmitted without the need to construct sqlparameter ...... Well, this article mainly introduces a small trick, that is, how to use Params object [].

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.