Here I established the connection first, after that I read the excel file schema into dropdown list using OleDbSchemaGuid.Tables.
I change the Autopostback property of DropDown list to true, to display the Excel file content for every selected sheet from Gridview.
In dropdownlist selectedIndexChanged event I wrote code like below.
Try
Dim filename As String = hf.Value
Dim con As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source='" & _
filename & "'; " & "Extended Properties=""Excel 8.0;HDR=No;IMEX=1;""")
Dim oledad As OleDbDataAdapter
Dim ds As New DataSet
oledad = New OleDbDataAdapter("select * from [" & ddl1.SelectedItem.Text & "]", con)
oledad.Fill(ds)
gv1.DataSource = ds.Tables(0).DefaultView
gv1.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
To display data also I established the connection again,if you want you can make global connection for that.
Whenever user selects the particular sheet the gridview displays the data of that sheet.
You can find source code for the sam below.
<< Previous Download source code here
Subscribe
Filter by APML