I am trying to select a single cell from an Excel workbook. I am using the following code.
strCN = GetExcelConnect ion("C:\Test\Ex cel.xls")
strCMD = "select * from [Sheet1$A1:A1]"
oleDbCN = New OleDb.OleDbConn ection
oleDbCN.Connect ionString = strCN
oleDbCN.Open()
oleDbCMD = New OleDb.OleDbComm and
oleDbCMD.Connec tion = oleDbCN
oleDbCMD.Comman dType = CommandType.Tex t
oleDbCMD.Comman dText = strCMD
ds = New DataSet
oleDbDA = New OleDb.OleDbData Adapter(oleDbCM D)
oleDbDA.Fill(ds )
dt = ds.tables(0)
The table that is returned contains zero records. The name of the first column is the value from cell A1. Also if my SQL statement would have been "select * from [Sheet1$A1:A3]" then I would have got 2 rows returned with the value from A1 being the column name and the values from A2 and A3 being the two row values.
My question is how do I get the value of cell A1. Yes, I could get it from the column name, but surely that is not the best practice.