Click here to Skip to main content
14,486,801 members
Rate this:
Please Sign up or sign in to vote.
How to export particular column values which does not have header to datagrid

...

dta = New OleDbDataAdapter("Select * from [linexcel$])

...

How can I specify the column(column B and D) instead of '*'. It does not have constant header.

...

What I have tried:

dta = New OleDbDataAdapter("Select  A1 from [linexcel$])
Posted
Updated 13-Mar-20 13:53pm
Comments
Richard MacCutchan 4-Mar-20 7:01am
   
I have tried a number of combinations based on suggestions provided by Google, but have not got a working solution. I suggest you just use the standard SELECT * construct and extract the fields you want manually. Alternatively you could look into using the Excel Interop features if you have Office installed.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use this:
Select  [F1] As ColumnA, [F2] AS ColumnB from [linexcel$]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

My Suggestion is using the EPP DLL for doing this is using the epp library gotten from github here

GitHub - JanKallman/EPPlus: Create advanced Excel spreadsheets using .NET[^]

reference their website is here

Features - EPPlus Software[^]

using the .net framework you can pull up their packages via Nuget

A basic Example lies here

Getting Started · EPPlusSoftware/EPPlus Wiki · GitHub[^]
   
Comments
Richard Deeming 4-Mar-20 14:43pm
   
It's a shame that EPPlus is moving to a noncommercial licence. I can understand why they're doing it, but I guess it means we'll have to be more careful about recommending it in future - if it costs money to use, then a recommendation could be seen as spam.
MarcusCole6833 4-Mar-20 15:04pm
   
Thank you for that!!
Rate this:
Please Sign up or sign in to vote.

Solution 3

Run initial select statement to obtain column names
dta = New OleDbDataAdapter("Select * from [linexcel$])
Dim tbl As New DataTable
dta.Fill(tbl)

' Column B and D would would be at index 1 & 3 respectively
Dim ColBName As String = tbl.Columns(1).ColumnName
Dim ColDName As String = tbl.Columns(3).ColumnName
dta  = New OleDbDataAdapter("Select " & ColBName & "," & ColDName & "  from [linexcel$]"
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100