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.