/ Published in: VB.NET
Doesn't do any validation, you would want to check if a
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Dim ofD As New OpenFileDialog ofD.ShowDialog() If ofD.FileName.Length = 0 Then Exit Sub Dim cS As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & ofD.FileName & ";" & _ "Extended Properties=Excel 8.0;" Dim cN As New OleDb.OleDbConnection(cS) cN.Open() Dim dA As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", cN) Dim dSet As New DataSet dA.Fill (dSet) tvDB.Nodes.Clear() Dim dT As DataTable = dSet.Tables(0) Dim nParent As TreeNode For iCol As Integer = 0 To dT.Columns.Count - 1 nParent = tvDB.Nodes.Add(dT.Columns(iCol).ColumnName) For iRow As Integer = 0 To dT.Rows.Count - 1 nParent.Nodes.Add (dT.Rows(iRow).Item(iCol)) Next nParent.Expand() Next dA.Dispose() dSet.Dispose() cN.Dispose()