Solution to the Problem of using MS Access in Enterprise Library-data block

Source: Internet
Author: User
This is because Enterprise Library-data block oralce has been used in the project as a server-side application. Now I want to create a desktop application. For uniformity, you are also prepared to use the Enterprise Library-data block for MS access. So I went online to find oledb of the Enterprise Library. Source code , And then manually compile and generate the DLL.

/Files/culturenet/oledbdata.zip

After configuration, useCodeAs follows:

Database DB = Databasefactory. createdatabase ( " Accessdb " );
String Sqlcommand =   " Select * From myresource " ;
Dbcommandwrapper = DB. getstoredproccommandwrapper (sqlcommand );
Dataset DS = DB. executedataset (dbcommandwrapper );
Datagrid1.datasource = DS. Tables [ 0 ];

An exception occurred during use.
The trail finds that the commandtype of the input command is storedprocedure.

There are two ways to avoid exceptions:

1. Use select * From myresource in access to create a query named source.

Use the following code: Database DB = Databasefactory. createdatabase ( " Accessdb " );
String Sqlcommand =   " Source " ;
Dbcommandwrapper = DB. getstoredproccommandwrapper (sqlcommand );
Dataset DS = DB. executedataset (dbcommandwrapper );
Datagrid1.datasource = DS. Tables [ 0 ];

2. Specify commandtype as text directly in the code

The Code is as follows: Database DB = Databasefactory. createdatabase ( " Accessdb " );
String Sqlcommand =   " Select * From myresource " ;
Dbcommandwrapper = DB. getstoredproccommandwrapper (sqlcommand );
Dbcommandwrapper. Command. commandtype = Commandtype. text;
Dataset DS = DB. executedataset (dbcommandwrapper );
Datagrid1.datasource = DS. Tables [ 0 ];


you can use the getsqlstringcommandwrapper method to replace getstoredproccommandwrapper. It must have been dizzy last night, and I forgot all the methods I used before.

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.