Search code examples
c#exceloledbdatareader

OleDbDataReader, C# - What is the maximum limit of the number of rows OleDbDataReader can retrieve from an excel file?


I am using OleDbDataReader (C#) to read 93081 rows from an excel file but it doesn't seem to read all the rows. It only reads 27545 out of the 93081 rows. When I read another file which only has 15941 rows, it doesn't pose any problem and retrieves all the rows.

I have included IMEX=1 in connection string as mentioned by many people online, even though the data type is the same throughout the excel file.

What is the maximum limit of the number of rows OleDbDataReader can read from an excel file?

Edit: Added code

var loc = "C:\\Users\\random\\Desktop\\Test.xlsx";
var myConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=\""+ loc + "\";Extended Properties=\"Excel 8.0;IMEX=1\";");
var myCommand = new OleDbCommand();   

myConnection.Open();
myCommand.Connection = myConnection;
var sql = "Select * from [Sheet2$]";
myCommand.CommandText = sql;
var dataReader = myCommand.ExecuteReader();
var insert = "";
var result = "";

DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Request", typeof(string));
table.Columns.Add("Decoded_Request", typeof(string));

while (dataReader.Read()){
      insert = dataReader["Request"].ToString();
      result = HttpUtility.UrlDecode(insert);
      table.Rows.Add(i, insert, result);
      i++;
      Console.WriteLine(i);
}

Thank you!


Solution

  • For those who come in to find answer ...I think you are using old excel driver . Excel had limitation of 65536 rows .

    In this example rows 27546 = 93081 - 65536