Use of SqlHelperSqlHelper in ASP. NET data access layer

Source: Internet
Author: User

Use of ASP. NET SqlHelper in ASP. NET data access layer

If you do not use the ASP. NET data access layer, there 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.

This document describes how to use ASP. NET 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 ASP. NET data access layer?

If you do not use the data access layer, there 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 relational diagram of ASP. NET SqlHelper:

 

The following describes how to use it.

Execute a stored procedure without return values:

Create procp_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 [].

The use of ASP. NET SqlHelperSqlHelper in ASP. NET data access layer is introduced to you here. I hope you have some knowledge about ASP. NET SqlHelperSqlHelper.

  1. Comparison of ASP. NET data binding controls
  2. Comparison between ASP. NET's GridView and DataGrid controls
  3. Analysis of ASP. NET data cache mechanism
  4. Introduction to data caching in ASP. NET data cache
  5. Implementation of ASP. NET data collection

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.