Click here to Skip to main content
Rate this: bad
good
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
CAS1224515
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

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:
 
SELECT SalesMonth, TotalSales, PercentageChange1Year 
FROM [Sheet1$A1:E24]

Source: Accessing Microsoft Office Data from .NET Applications[^]
 
Secondly, replace:
MyCommand = New OleDb.OleDbDataAdapter

with:
MyCommand = New OleDb.OleDbCommand
  Permalink  

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 20 May 2013
Copyright © CodeProject, 1999-2014
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