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

I am using VB.NET to query through an Excel SQL table using ADO.

The general way is as follows:

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

Which works fine. However, one of the headers is called 3, so I want to do:

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

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

dr("3") which will not work

Any ideas?

+3
source share
1 answer

When used (or implied) HDR=YESin a connection string, an invalid column name will be replaced by the ordinal position of the column, supplemented by a letter F.

, 3 Excel, F5.

+1

Source: https://habr.com/ru/post/1790658/


All Articles