ExecuteReader on empty Excel range hangs

A

Anber

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
8.0;HDR=NO;IMEX=1"""
ExcelConnection = New OleDbConnection(ExcelConnectionString)
ExcelConnection.Open()

Dim command As New OleDbCommand("SELECT * FROM [Sheet1$A1:B2]",
ExcelConnection)
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top