Listing 11-4: Accessing Employees.xls using the ODBC data provider
Private Sub Form1_Load(ByVal senderAs Object,ByVal e As System.EventArgs)
' Connection string for ODBC Excel Driver
Dim ConnectionStringAs String ="Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\Employees.xls"
Dim conn As New OdbcConnection(ConnectionString)
' Table in Excel can be thought of as sheets and are queried as shown
Dim sql As String = "Select EmployeeID, FirstName, LastName FROM Employees"
conn.Open()
Dim da As New OdbcDataAdapter(sql, conn)
Dim ds As New DataSet()
da.Fill(ds,"Employees")
dataGrid1.DataSource = ds.DefaultViewManager
listBox1.DataSource = ds.DefaultViewManager
listBox1.DisplayMember = "Employees.FirstName"
End Sub
The output of listing 11-4 looks like figure 11-36.