简体   繁体   English

使用Sql连接字符串提取Excel数据

[英]Extracting Excel data using Sql connection string

My intention here is to render the excel data in a table, using a datatable, so opened an odbc connection and loaded the datatable like this: 我的意图是使用数据表在表格中呈现excel数据,因此打开了odbc连接并像这样加载数据表:

System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};Driverid=790;Dbq=C:\Users\*******\Documents\Book1.xlsx;DefaultDir=C:\Users\******\Documents;HDR=YES);
conn.Open();
DataTable dataTable = new DataTable();
string con = "select * from [sheet1$]";
System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand(con, conn);
System.Data.Odbc.OdbcDataReader dr = cmd.ExecuteReader();
dataTable.Load(dr);

But insted getting an error like this 但是插入这样的错误

ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application 错误[IM014] [Microsoft] [ODBC驱动程序管理器]指定的DSN包含驱动程序和应用程序之间的体系结构不匹配

So actually whats' the root cause ? 那么实际上是什么原因呢?

This suggests 表明

"changing the Platform target project setting from Any CPU to x86."

will help. 会有所帮助。 The root cause is, as the error says, a mismatch between the database driver and your application. 如错误所述,根本原因是数据库驱动程序与应用程序之间的不匹配。

These docs say 这些文档

If you use the 64-bit odbcad32.exe to configure or remove a DSN that connects to a 32-bit driver, for example, Driver do Microsoft Access (*.mdb), you will receive the following error message: The specified DSN contains an architecture mismatch between the Driver and Application To resolve this error, use the 32-bit odbcad32.exe to configure or remove the DSN. 如果您使用64位odbcad32.exe来配置或删除连接到32位驱动程序的DSN,例如Driver do Microsoft Access(* .mdb),则会收到以下错误消息:指定的DSN包含驱动程序和应用程序之间的体系结构不匹配要解决此错误,请使用32位odbcad32.exe来配置或删除DSN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM