Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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 Smile | :)
Posted 20-May-13 6:41am
ThePhantomUpvoter at 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 at 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
0 OriginalGriff 450
1 Suvendu Shekhar Giri 130
2 Abhinav S 126
3 Jochen Arndt 100
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,870
2 Peter Leow 4,984
3 Kornfeld Eliyahu Peter 3,300
4 Maciej Los 2,456

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 20 May 2013
Copyright © CodeProject, 1999-2015
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