-5

我想通过文本框控件过滤我的数据视图,但是当我运行程序时它说以下错误

“找不到表 0”

这是我的代码

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.KeyPress

        Dim conn As New OleDbConnection
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + IO.Directory.GetCurrentDirectory + "\Kyc.mdb"
        conn.Open()
        Dim cmdfilter As String = " select ID as الرقم_الوطني,fname as الاسم_الاول,sname as الاسم_الثاني,thname as الاسم_الثالث,finame as الاسم_الرابع from O_name "
        Dim dataadabtar As New OleDbDataAdapter(cmdfilter, conn)
        Dim ds As New DataSet
        Dim dsview As DataView
        Dim bs As New BindingSource
        dsview = ds.Tables(0).DefaultView
        bs.DataSource = dsview
        bs.Filter = "الرقم_الوطني LIKE '" & TextBox1.Text & "'"
        DataGridView1.DataSource = bs
        conn.Close()
End Sub 

请帮我

4

2 回答 2

0

尝试这个

    Dim dataadabtar As New OleDbDataAdapter(cmdfilter, conn)
    Dim ds As New DataSet
    Dim dsview As DataView
    Dim bs As New BindingSource

    dataadabtar.Fill(ds);

    IF ds.Tables.Count > 0 Then
      dsview = ds.Tables(0).DefaultView
      bs.DataSource = dsview
      bs.Filter = "الرقم_الوطني LIKE '" & TextBox1.Text & "'"
      DataGridView1.DataSource = bs
    END IF;
于 2013-09-27T14:29:42.790 回答
0

错误来自您的这部分代码..

Dim ds As New DataSet
....
dsview = ds.Tables(0).DefaultView

你从不分配 ds

于 2013-09-27T14:27:34.030 回答