帮助为Excel文件的OLEDB连接字符串

问题描述:

时遇到的问题是,数据适配器在每列中观察仅在第一行,以确定数据类型。在我的情况下,第一列SKU是第500行,那么我正好有SKU的这是混合的数字和字母数字。那么,最终发生的事情是在SKU列行留空,但我仍然可以为每个列行中的其他信息。

The problem i'm having is that the data adapter is looking at only the first row in each column to determine the data type. In my case the first column "SKU" is numbers for the first 500 rows then I happen to have SKU's which are mixed numbers and letters. So what ends up happening is rows in the SKU column are left blank, but I still get the other information for each column row.

我相信这是一个控制和我目前的设置它应该工作在连接字符串,但事实并非如此。

I believe it is the connection string that controls that and with my current settings it should work, however it is not.

连接字符串:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx" + @";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";



ImportMixedTypes=Text;TypeGuessRows=0

应该是重要的关键词,看0行,只使用文本作为值类型的一切。

Should be the important keywords, look at 0 rows and just use text as the value types for everything.

在创可贴我已经穿上这是使第一排在s preadsheet字母和数字的混合,特别离开该行出我的查询。

The "bandaid" I have put on this is to make the first row in the spreadsheet a mixture of letters and numbers and specifically leave that row out in my query.

不幸的是,你不能设置 ImportMixedTypes TypeGuessRows 从连接字符串,因为这些设置是在注册表中定义。对于ACE OLEDB驱动程序,它们储存在

Unfortunately, you can't set ImportMixedTypes or TypeGuessRows from the connection string since those settings are defined in the registry. For the ACE OleDb driver, they're stored at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel

在注册表中。因此,可以简化您的连接字符串:

in the registry. So, you can simplify your connection string to:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;""";

一旦您设置 TypeGuessRows 0 ImportMixedTypes 文本在注册表中,你应该得到你所期望的行为。你可能会,但是,如果你发现进口表现不太理想考虑使用像1000,而不是零适当大的数字。

Once you set TypeGuessRows to 0 and ImportMixedTypes to Text in the registry, you should get the behavior you are expecting. You might, however, consider using a suitably large number like 1000 instead of zero if you find import performance to be less than ideal.