我想根据两个文本框(名字(fname
)和第二个名字(sname
)过滤我的DataGridView,但它只是根据fname
这是我的代码:
Try
Dim conn As New OleDbConnection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + IO.Directory.GetCurrentDirectory + "\Kyc.mdb"
Dim cmdfilter As String = " select ID as الرقم_الوطني,fname as الاسم_الاول,sname as الاسم_الثاني,thname as الاسم_الثالث,finame as الاسم_الرابع from O_name where fname like '%" & fname.Text & "' OR sname like '%" & sname.Text & " ' "
Dim cmdcommand As New OleDbCommand
Dim dataadabtar As New OleDbDataAdapter
Dim table As New DataTable
With cmdcommand
.CommandText = cmdfilter
.Connection = conn
End With
With dataadabtar
.SelectCommand = cmdcommand
.Fill(table)
End With
DataGridView1.DataSource = table
DataGridView1.DataSource = Nothing
For i = 0 To table.Rows.Count - 1
With DataGridView1
.Rows.Add(table.Rows(i)("الرقم_الوطني"), table.Rows(i)("الاسم_الاول"), table.Rows(i)("الاسم_الثاني"), table.Rows(i)("الاسم_الثالث"), table.Rows(i)("الاسم_الرابع"))
End With
Next
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
答案 0 :(得分:0)
Dim cmdfilter As String = " select ID as الرقم_الوطني,fname as الاسم_الاول,sname as الاسم_الثاني,thname as الاسم_الثالث,finame as الاسم_الرابع from O_name where fname like '%" & fname.Text & "' OR sname like '%" & sname.Text & " ' Order by fname,Sname"
第一个偏好给fname和第二个偏好给sname