Net Call the method of stored procedures in Access

xiaoxiao2021-03-06  99

Using the stored procedure in SQL Server is a more familiar. Not long ago, you have made a small stuff. The database is used by the MS Access database, and it is also important to try whether the stored procedure is feasible. After all, the relationship between the stored procedures and the code is not very large, and the changes in the database and stored procedures are not to change the encoding. The following is posted on my code, everyone will find that in fact, the stored procedure that calls SQL Server is exactly the same, and different is only the name of the stored procedure.

Take the delete person information as an example: 1. Here is a piece of code of the data access layer, and the stored procedure is called directly.

Public class person {// // defines the stored procedure, note that the stored procedure here is enclosed in []. private const string ASP_PERSON_INSERT = "[asp_Person_Insert]"; private const string ASP_PERSON_UPDATE = "[asp_Person_Update]"; private const string ASP_PERSON_DELETE = "[asp_Person_Delete]"; ................. .................. private const string parm_person_personid = "@ personid"; ...................... ..........

private OleDbParameter [] GetDeleteParam (int PersonID) {OleDbParameter [] param = new OleDbParameter [] {new OleDbParameter (PARM_PERSON_PERSONID, OleDbType.Integer)}; param [0] .Value = PersonID; return param;}

///

/// Remove person information /// /// Nost /// successfully returns true; failed to return false < / returns> Public Bool Delete (int ") {// ASP_PERSON_DELETE stored procedure name.

OLEDBPARAMETER [] param = this.getDeleteParam (PERSONID); try {/// The mode has no change. INT i = utility.tools.createoledbcommandexecutenonquery (asp_person_delete, param); if (i> 0) {return true;}} catch {} returnaf false;}

2. Let's take a look at the difference between the Access database with SQL Server:

The stored procedures in the Access database are stored in the "query", open your access database, select "Query", select "New", build a simple query first. Select the table and the required fields and the required parameters. At this time, select the SQL view in the toolbar, you can see the following statement:

Parameters [Personid] short; delete * from personfowhere [PersoniD] = [Personid] = [Personid]; If the parameter is more, please refer to: parameters [id] short, [parentid] short, [organname] text (255), [Numbe ] Text (255), [OtherName] text (255), [CodeId] text (255), [OrganSpec] text (255), [OrganProperty] text (255), [OutlayType] text (255), [managementEpart] Text (255), [setuptime] datetime, [passDepart] text (255), [Organnum] short, [Personnnum] short, [passnumber] text (255), [address] text (255), [JPERSON] text (255) , [Tel] Text (255), Yearcheck Text (255);

Finally, save your code and try it. In addition, there is no SQL Server's querier, so you have to test your stored procedures in Access, you will be more troublesome: Right-click your stored procedure, select "Open", but the parameters do not enter errors. The write stored procedures in Access are troublesome. After all, it is not like SQL Server to support the stored procedures, so it is necessary to pay special and strongly recommend that you will always save.

转载请注明原文地址:https://www.9cbs.com/read-103656.html

New Post(0)