Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Using ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
txtExcelPath.Text = ofd.FileName
End If
End Using
I got the file path from above coding.i don't know how to retrieve the column names from the file.Please help me.
Thanks in Advance
Posted

1. You can connect by ADODB connection with excel sheet

CSS
Dim cn as ADODB.Connection
Set cn = New ADODB.Connection
With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=C:\MyFolder\MyWorkbook.xls;" & _
"Extended Properties=Excel 8.0;"
    .Open
End With


2. Then get all data to a dataset and then you can get column name by following line

VB
dt.Columns[0].ColumnName
 
Share this answer
 
v3
Comments
[no name] 1-May-14 17:26pm    
i am using sql server connection.Will this work for that too.
Manoj Kumar Choubey 2-May-14 4:09am    
I think, You want to copy data from excel sheet to sql server by mapping columns right ?<br><br>
You can not import/read excel sheet from sql server connection object directly, You can make stored procedure for the same and call it and pass excel sheet path as parameter, 2 you can use Excel Objects Library or 3 you can connect with ADODB connection that is free or open source library to read Excel files.
Manoj Kumar Choubey 2-May-14 4:14am    
You can follow following link
http://www.aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-into-SQL-Server-Database-in-ASP.Net.aspx
See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^], which includes VB.NET sample code.
 
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