ExecuteReader on empty Excel range hangs RRS feed

  • Question

  • With VB.NET (Visual Studio 2005), I am trying to read a range of cells from
    an Excel-sheet, where the first rows and columns are empty. It's a sheet I
    just created in Excel, so there has never been data in the first rows and
    columns before. The actual data in the sheet starts at C4.
    When I try to read a block of values which contains only empty cells, f.e.
    A1:B2, ExecuteReader hangs.

    Here is my code:

    Dim ExcelConnectionString As String
    Dim ExcelConnection As OleDbConnection

    ExcelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    ExcelConnectionString += "C:\Temp\Test1.xls"
    ExcelConnectionString += ";Extended Properties=""Excel
    ExcelConnection = New OleDbConnection(ExcelConnectionString)

    Dim command As New OleDbCommand("SELECT * FROM [Sheet1$A1:B2]",
    Dim reader As OleDbDataReader
    reader = command.ExecuteReader()

    When I open Excel, add values to the above range, then remove these values
    and start the code again, the code works fine, the reader contains no rows
    and that's what I want.

    Does anyone know what's happening here?

    Or is there a way to determine the last filled cell in an Excel sheet?
    Tuesday, October 28, 2008 3:18 PM

All replies

  • Do you get any exception? Does it hand indefinitely or you get some sort of timeout or other error after certain period of time?


    Wednesday, October 29, 2008 10:25 AM