Click here to Skip to main content
13,253,507 members (51,190 online)
Rate this:
Please Sign up or sign in to vote.
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 20-May-13 6:41am
ThePhantomUpvoter 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.
ThePhantomUpvoter 20-May-13 11:51am
Just as a side note, you would be missing a "]" at the very least in your query.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, have a look here:
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:

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

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

Secondly, replace:
MyCommand = New OleDb.OleDbDataAdapter

MyCommand = New OleDb.OleDbCommand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 20 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100