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