Combobox A will load the DISTINCT Street name from Microsoft Access, when user selects the Street name, Combobox B will load the House Number of the selected Street name. Below are my codes:
Private Sub tsmiAddress_Click(sender As Object, e As EventArgs) Handles tsmiAddress.Click
lblSearch.Text = "Search (Address)"
If oledbCon.State = ConnectionState.Closed Then
oledbCon.Open()
End If
Dim oledbCmd As New OleDbCommand("SELECT DISTINCT Jalan FROM House", oledbCon)
Dim oledbCmd2 As New OleDbCommand("SELECT House_No FROM House WHERE Jalan = '" & cmbJalan.SelectedValue.ToString & "'", oledbCon)
Dim oledbDr As OleDbDataReader = oledbCmd.ExecuteReader()
Dim oledbDr2 As OleDbDataReader = oledbCmd2.ExecuteReader()
If oledbDr.HasRows Then
While oledbDr.Read()
cmbJalan.Items.Add(oledbDr.Item(0))
End While
While oledbDr2.Read()
cmbNo.Items.Add(oledbDr2.Item(0))
End While
cmbJalan.SelectedIndex = 0
cmbNo.SelectedIndex = 0
oledbDr.Close()
End If
oledbCon.Close()
End Sub
But I get an error:
An unhandled exception of type 'System.NullReferenceException' occurred in ThePeak.exe
Additional information: Object reference not set to an instance of an object.