Mixed Data Type in Excel, IMEX Doesn't Work

2019-04-03 02:07发布

I am trying to export xls into datatable. Below is my connection string.

string path = //xls source path
OleDbConnection MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + path + "';Extended Properties='Excel8.0;IMEX=1;TypeGuessRows=0;HDR=No;ImportMixedTypes=Text'");

I set IMEX=1 and all the other extended properties as I have to deal with mixed datatypes.

Even though I set the connection like that yet I still produced error.

There are no error messages, but the inconsistent rows (who don't follow the majority datatype are set to null instead).

Can someone tell me what did I miss? Btw, I am using the OleDbDataAdapter & Fill(DataSet) method.

1条回答
smile是对你的礼貌
2楼-- · 2019-04-03 02:41

Are you sure that TypeGuessRows=0; and ImportMixedTypes=Text; are working from connection string and should not be modified in registry (HKEY_LOCAL_MACHINE\SOFTWARE\[Wow6432Node\]Microsoft\Jet\4.0\Engines\Excel)? AFAIK this settings are read from registry. ImportMixedTypes=Text is usually by default, but TypeGuessRows=8, and should be set to 0 as in your connection string.

查看更多
登录 后发表回答