At first glance I have the same problem as many persons had before and I found many questions and answers about my problem but none of them helped me.
I perform importing from MS excel file (file XLS) in NET by using ADO NET. The file contains mixed types in the same column: numbers and text, and the well known problem occurs - text format is not recognized and the data are lost.
I use the following connection string with recommended parameters:
string strConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text\";", pathname);
This is my code:
OleDbConnection sqlConn = new OleDbConnection(this.strConnectionString);
sqlConn.Open();
OleDbDataAdapter sqlAdapter = new OleDbDataAdapter();
string sql = "SELECT * FROM [" + sheetName + "]";
OleDbCommand selectCMD = new OleDbCommand(sql, sqlConn);
sqlAdapter.SelectCommand = selectCMD;
DataTable dt = new DataTable(sheetName);
sqlAdapter.Fill(dt);
I tested it under NET 3.5 (x86) and NET 4.0 (x86) (also tested as windows exe and asp net version), and the problem remains.
I don't know if I do something wrong but I've spent many hours and problem still remains.