ComboBox - I'm really stuck

  • Thread starter Thread starter KentL
  • Start date Start date
K

KentL

I have a bound data form with some text boxes and several comboboxes. I am
having no luck in getting the comboboxes to work. I sure could use some
help with this. I have the following code in the load event of my form.

Dim dtProj As System.Data.DataTable

Dim connProj As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=c:\CMMS\CMMS.mdb")

Dim daProj As New OleDb.OleDbDataAdapter("SELECT * FROM
tblApprovedProjects", connProj)

daProj.Fill(dtProj) ' <--- Error Here!

Me.cboProjectNumber.DataSource = dtProj

Me.cboProjectNumber.DisplayMember = "ProjectNumber"

Me.cboProjectNumber.ValueMember = "ProjectNumber"



The form works ok, showing the data as it should when I don't have any code
for the comboboxes..

When I run the form with the combobox code I get an error - An unhandled
exception of type 'System.ArgumentNullException' occurred in system.data.dll
Additional information: Value cannot be null. The line daProj.Fill(dtProj)
is where I get this error.

I can't seem to figure out what is wrong. Is this the correct way to get
the table records to populate the combobox? If so, what am I doing wrong?

Thanks in advance!

Kent
 
You did not instantiate an instance of a DataTable.

This line:

Creates the variable but it is still Nothing.
Try this instead:

Dim dtProj As New System.Data.DataTable

Chris
 
Thanks Chris
That worked great!

Chris said:
You did not instantiate an instance of a DataTable.

This line:


Creates the variable but it is still Nothing.
Try this instead:

Dim dtProj As New System.Data.DataTable

Chris
 
Back
Top