Importing data from an Excel sheet
Posted in:
Data Access
By dePoPo
Jun 6, 2009 - 11:58:40 AM
' --- Attach the excel sheet linked to in s_filename
' the top row of the excel sheet contains the field names
Dim s_connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & s_filename & ";Extended Properties=Excel 8.0"
Dim myconnection As New OleDbConnection(s_connectionstring)
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [Import$]", myconnection) ' Get all data from the sheet named import
Dim mydataset As DataSet = New DataSet()
myadapter.Fill(mydataset)
Dim myrow As DataRow
For Each myrow In mydataset.Tables(0).Rows 'Show results in output window
' --- Here you can reference the fields with myrow("fieldname")
MsgBox(myrow("fieldname"))
Application.DoEvents()
Next
myconnection.Close()
Visitor Comments