Return to Snippet

Revision: 37917
at December 20, 2010 17:00 by brettville


Initial Code
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.Close()
cN.Dispose()

Initial URL

                                

Initial Description
Doesn't do any validation, you would want to check if a

Initial Title
Use OLEDB To Read An Excel File

Initial Tags
sql, excel

Initial Language
VB.NET