Chapter 5 Exercise 1 ComboBox not filling
I am working through the book and have tried the solutions code from appendix c for Chapter 5 exercise 1 but the combobox doesn't populate with any data. I'm not getting any errors just no data in the comboBox. Here is the code I used. If someone could look it over and point out any errors I would be greatful
Thanks
Neal
****************
Imports System.Data
Imports System.Data.OleDb
PublicClassForm1
'form level variables
Private strConnectionString AsString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\ProjectTimeTracker.mdb;"
Private objConnection AsOleDbConnection
Private objCommand AsOleDbCommand
Private objDataAdapter AsOleDbDataAdapter
Private objDataTable AsDataTable
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
'initialize the Connection object
objConnection = NewOleDbConnection(strConnectionString)
'initialize the command object
objCommand = NewOleDbCommand("SELECT ProjectID, ProjectName FROM Projects", objConnection)
'initialize the DataAdapter object and set the SelectCommand property
objDataAdapter = NewOleDbDataAdapter
objDataAdapter.SelectCommand = objCommand
'initialize the DataTable object
objDataTable = NewDataTable
'populate the DataTable
objDataAdapter.Fill(objDataTable)
'bind the DataTable to the ComboBox
cboProjects.DataSource = objDataTable
cboProjects.DisplayMember = "ProjectName"
cboProjects.ValueMember = "ProjectID"
'clean up
objCommand.Dispose()
objCommand = Nothing
objConnection.Dispose()
objConnection = Nothing
objDataAdapter.Dispose()
objDataAdapter = Nothing
objDataTable.Dispose()
objDataTable = Nothing
EndSub
EndClass
|