Wednesday, October 17, 2007

How to Import Data from Excel File

This article provides a very simple example of how to query an Excel spreadsheet from an ASP.NET page using VB .NET. Check it out!

Sub Page_Load(sender As Object, e As EventArgs)
Dim ds As New DataSet()

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=""Excel 8.0;"""

Dim da As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
da.TableMappings.Add("Table", "Excel")
da.Fill(ds)

DataGrid1.DataSource = ds.Tables(0).DefaultView
DataGrid1.DataBind()
End Sub

Good Luck!

2 comments:

Chaw Su Su on March 11, 2009 at 5:43 PM said...

How to import data from multi-sheets of excel file? Pls write sample code.

Thanks
Chaw

ejuly on March 11, 2009 at 9:33 PM said...

Hi Chaw,

Please refer to this post -> Excel In .NET Application

Cheers!

 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template