vb.net - External table is not in the expected format error while trying to access Excel -
i trying access excel vb application using oledb connection . here connection string:
<add key="excelconnection" value="provider=microsoft.ace.oledb.12.0;data source={0};extended properties="excel 12.0 xml;hdr=no;imex=1;maxscanrows=1000;readonly=false;"" />
here code:
dim connection new system.data.oledb.oledbconnection(excelconnectionstring) connection .open() dim schtbl datatable = connection .getoledbschematable(system.data.oledb.oledbschemaguid.tables, nothing) dim dbadapter system.data.oledb.oledbdataadapter dim execquery string dim rtndata system.data.datatable execquery = "select * [" & schtbl.rows.item(0)("table_name") & "]" dbadapter = new system.data.oledb.oledbdataadapter(execquery , excelconnectionstring) dbadapter.fill(rtndat ) dbadapter.dispose() connection .close() schtbl .reset()
what problem ,the above working 70% of times rest of times getting following error:
system.data.oledb.oledbexception (0x80004005): external table not in expected format.
could please me why @ times getting error .is there way rectify or other way achive same result.
any appreciated.
thanks
external table not in expected format.
typically occurs when trying use excel 2007 file.
using following connection string seems fix problems.
dim path string = yourfilepath dim connstr string = "provider=microsoft.ace.oledb.12.0;data source=" + path + ";extended properties=excel 12.0;"
edit
some times may fail in case when using .xlsx
file.if case should install jet database engine in pc override errors.it availale http://www.microsoft.com/downloads/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en
Comments
Post a Comment