从另一个Combobox的选定项目加载Combobox与Microsoft Access

时间:2017-03-04 12:16:16

标签: vb.net ms-access combobox

Combobox A将从Microsoft Access加载DISTINCT Street名称,当用户选择街道名称时,Combobox B将加载所选街道名称的门牌号码。以下是我的代码:

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

但是我收到了一个错误:

  

类型'System.NullReferenceException'的未处理异常   发生在ThePeak.exe

     

附加信息:对象引用未设置为的实例   对象

0 个答案:

没有答案