473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Select Single Cell From Excel

PCK
I am trying to select a single cell from an Excel workbook. I am using the following code.

strCN = GetExcelConnection("C:\Test\Excel.xls")
strCMD = "select * from [Sheet1$A1:A1]"
oleDbCN = New OleDb.OleDbConnection
oleDbCN.ConnectionString = strCN
oleDbCN.Open()
oleDbCMD = New OleDb.OleDbCommand
oleDbCMD.Connection = oleDbCN
oleDbCMD.CommandType = CommandType.Text
oleDbCMD.CommandText = strCMD
ds = New DataSet
oleDbDA = New OleDb.OleDbDataAdapter(oleDbCMD)
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.
Nov 20 '05 #1
1 9056
On Wed, 10 Dec 2003 07:21:19 -0800, PCK <an*******@discussions.microsoft.com> wrote:

¤ I am trying to select a single cell from an Excel workbook. I am using the following code.
¤
¤ strCN = GetExcelConnection("C:\Test\Excel.xls")
¤ strCMD = "select * from [Sheet1$A1:A1]"
¤ oleDbCN = New OleDb.OleDbConnection
¤ oleDbCN.ConnectionString = strCN
¤ oleDbCN.Open()
¤ oleDbCMD = New OleDb.OleDbCommand
¤ oleDbCMD.Connection = oleDbCN
¤ oleDbCMD.CommandType = CommandType.Text
¤ oleDbCMD.CommandText = strCMD
¤ ds = New DataSet
¤ oleDbDA = New OleDb.OleDbDataAdapter(oleDbCMD)
¤ 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.

Do you have HDR=No in your connection string? It's probably using the first row/cell value as the
column name.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
8
by: carlospedr | last post by:
I have to insert data from about 30 tables into a single table (Users), to do so i used a cursor and a bit of dynamic sql, this should work fine if the tables have to do the select from had the...
18
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
7
by: ashley.ward | last post by:
We have been using VB6 to develop small custom apps that access an Oracle database, in order to extend a larger product that is developed by our colleagues in Germany (who use C++ and Java). As...
2
by: Brian Parker | last post by:
I need to format text in cell in an Excel worksheet and I need to do this using C#. I've seen code that will set the format for the whole cell, but I just need to format one character in that...
7
by: khunohm | last post by:
I would like to know how to select each item of data from text file transfer to each column in excel file. source 1..159662 /organism="Candidatus...
0
by: hne | last post by:
Hi friends, I have an application, written in C#, in which I am updating an Excel spreadsheet with data I pull from a sql database. When I try to select a cell in where I want to begin inserting my...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
2
by: patrick.waldo | last post by:
Hi all, I am trying to figure out a way to read colors with xlrd, but I did not understand the formatting.py module. Basically, I want to sort rows that are red or green. My initial attempt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.