Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using an OleDb in C# connection to read data from an Excel sheet. And fill it in a Datatable.

The sheet contains 275 rows and 27 columns. After I read it, Rows 1,2 and 3 are empty. All the other rows are filled correctly.

Anyone have an idea on the problem?

Here is my code:

C#
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                "Data Source=" + "C:/Sheets/DataSheet.xls" + ";Extended Properties=Excel 12.0;";

objConn = new OleDbConnection(connString);

string Querry = "SELECT * FROM [Sheet1$]";
OleDbCommand objCmd = new OleDbCommand(Querry, objConn);

DataTable Table = new DataTable();
objAdapter1.SelectCommand = objCmd;
objAdapter1.Fill(Table);
Posted

1 solution

You could try to add HDR=No;IMEX=1 to your connection string. If you don't have a header row and in case you have mixed data types in columns.
C#
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Sheets/DataSheet.xls;Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\";";
 
Share this answer
 
v2
Comments
Youssef_Keyrouz 6-Sep-11 13:22pm    
Thank you for your responce. I think I need to specify IMEX=1 (because I just noticed that it is only reading cells with numbers and not strings)
but It is giving me an error "
"System.Data.OleDb.OleDbException: Could not find installable ISAM." any idea how to fix this?
Wendelius 6-Sep-11 15:05pm    
There was a problem with the connection string. Answer is now updated, check if it helps.
Youssef_Keyrouz 7-Sep-11 3:47am    
Thank you very much. it worked :)
Wendelius 7-Sep-11 3:49am    
That's great to hear :) You're welcome.
ali sbeiti 23-Feb-23 3:35am    
thank you, this solved my issue after 2 days of searching.
on my local machine I was able to load 30+ k rows from the excel but when I upload it to the iis server, It loads only 10k rows.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900