Adohelper is an abstract data handler class in MS daab. The sqlhelper derived from it is widely used. pdf. NET data development framework implements its own implementation according to the adohelper interface. The following describes how to use it to use the stored procedure.
Two features of PDF. Net: SQL-MAP and oql examples in our project and frameworkProgramMany users are used, but few people directly use adohelper. Therefore, new colleagues found another sqlhelper for convenience. In fact, this is not necessary.
Assume that there is a MySQL database test and a stored procedure proc_user1. The following is an example of using the stored procedure.
1. First configure app. config/Web. config:
<? XML Version = " 1.0 " Encoding = " UTF-8 " ?> < Configuration > < Connectionstrings > < Add Name = " Default " Connectionstring = " Server = 192.168.xx.xx; user id = root; Password = xxxx; database = test " Providername = " Pwmis. dataprovider. Data. MySQL, pwmis. mysqlclient " /> </ Connectionstrings > </ Configuration >
2. Use the following in the program:
Pwmis. dataprovider. Data. adohelper DB = pwmis. dataprovider. Adapter. mydb. getdbhelperbyconnectionname ("Default");// Pwmis. dataprovider. Data. adohelper DB = pwmis. dataprovider. Adapter. mydb. instance;// MySQL stored procedure test;// The parameter name can be added with the @ symbol, for example, @ page1Dataset ds1 = dB. executedataset ("Proc_user1", Commandtype. storedprocedure,NewSystem. Data. idataparameter [] {dB. getparameter ("@ Page1", 22 )});
3. Description:
You can use mydb. instance or the connection configuration name to obtain the data access object instance.
Mydb. getdbhelperbyconnectionname ("Default");
"Default" is the connection name in the configuration file;
To use a stored procedure, you only need to pass the stored procedure name, commandtype. storedprocedure, and parameter array.
PS:
Although this article describes the usage of MySQL, if the various databases supported by the pdf. NET Framework can use stored procedures,The usage is consistent..