Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Use this:
SQL
Select  [F1] As ColumnA, [F2] AS ColumnB from [linexcel$]
 
Share this answer
 
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[^]
 
Share this answer
 
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!!
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$]"
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900