我想通过Textbox控件过滤我的Dataview,但是当我运行程序时,它会显示以下错误
“找不到表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
请帮帮我
答案 0 :(得分:0)
错误来自代码的这一部分..
Dim ds As New DataSet
....
dsview = ds.Tables(0).DefaultView
您永远不会指定ds
答案 1 :(得分: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;