Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Excel using ADO from VB.NET when a column name is a number

I am using VB.NET to query via SQL an Excel spreadsheet using ADO.

The general way is like this:

SELECT [firstname], [secondname] FROM [Sheet1$]

Which works perfectly
However, one of the headings is called 3, so I want to do:

SELECT [firstname], [secondname], [3] FROM [Sheet1$]

However, this does not work. I know I can use * to get all columns, but later on I want to use (using dataReader):

dr("3") which won't work

Any ideas?

like image 342
user159603 Avatar asked Feb 04 '26 02:02

user159603


1 Answers

When using (or implying) HDR=YES in the connection string, an illegal column name will be replaced with the column's ordinal position appended with the letter F.

For example, if your column named 3 is the fifth column in the Excel Range then its name will be considered to be F5.

like image 122
onedaywhen Avatar answered Feb 06 '26 19:02

onedaywhen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!