0

我想与组合框绑定。但这是错误“对象引用未设置为对象的实例”。

此代码:

Private Sub cbSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSection.SelectedIndexChanged
        Dim Find As Boolean = False
        Dim ds2 As New DataSet
        Dim sb2 As New StringBuilder
        Dim da2 As New SqlDataAdapter

        sb2.Remove(0, sb2.Length)
        sb2.Append("SELECT DISTINCT Team")
        sb2.Append(" FROM Employee")
        sb2.Append(" WHERE (Section='" & cbSection.SelectedValue & "')")
        sb2.Append(" ORDER BY Team")
        Dim sqlTeam As String = sb2.ToString()

        If Find = True Then
            ds2.Tables("Team").Clear() >>>>>>> This Error
        End If

        da2.SelectCommand.CommandText = sqlTeam
        da2.Fill(ds2, "Team")
        If ds2.Tables("Team").Rows.Count <> 0 Then
            Find = True
            With cbTeam
                .DisplayMember = "Team"
                .ValueMember = "Team"
                .DataSource = ds2.Tables("Team")
            End With
        Else
            Find = False
        End If
    End Sub

我检查对象它是正确的。但现在出错了。

谢谢你的时间。:)

4

0 回答 0