Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello so far I followed your code example for Working with MS Excel(xls / xlsx) Using MDAC and Oledb.

I'm trying to get data from a specific cell from my worksheet in Excel 2010 however it seems to be giving me some issues. Here is my code below

MyCommand = New OleDb.OleDbDataAdapter( _
"select * from [" & SheetList(6), & "$B4", MyConnection)

I know there has to be a simple fix, maybe a bracket out of place or something. I greatly appreciate any help you may be able to give me. Thanks :)
Posted
Comments
[no name] 20-May-13 11:50am    
You would probably need to ask where ever you got this code from. And when you do, "some issues" is not very informative. You would need to describe what the issues are.
[no name] 20-May-13 11:51am    
Just as a side note, you would be missing a "]" at the very least in your query.

1 solution

First of all, have a look here:
Quote:
Your first option is to specify a worksheet and, optionally, a set of cells on that sheet. You need to make sure that the worksheet name is followed by a dollar sign and then, optionally, a cell set. The cell set is specified by the starting cell and terminating cell of the set, separated by a colon. This whole data identification string is then enclosed in brackets. A SELECT statement using this type of syntax might look like this:

SQL
SELECT SalesMonth, TotalSales, PercentageChange1Year 
FROM [Sheet1$A1:E24]


Source: Accessing Microsoft Office Data from .NET Applications[^]

Secondly, replace:
VB
MyCommand = New OleDb.OleDbDataAdapter

with:
VB
MyCommand = New OleDb.OleDbCommand
 
Share this answer
 

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