求助!!麻烦高手帮我改一下vb access 数据查询 代码,实现模糊查询。谢谢了。
数据库中的字段是gaowei想要的结果就是输入gao或者wei或者gaowei或者gaowei都能出结果。现在的代码只有输入gao或gaowei能出结果,输入wei或ga...
数据库中的字段是 gao wei 想要的结果就是输入 gao 或者 wei 或者 gao wei 或者 gaowei都能出结果。现在的代码只有输入 gao 或 gao wei 能出结果,输入 wei 或 gaowei 不能查到。
希望高手帮我改一下后能实现模糊查询。
关键代码如下:
Dim objRs As New Recordset, objCn As Connection, strFilter$
Private Sub cmdQuery_Click()
If Trim(requnum) = "" Then
strFilter = ""
Else
strFilter = "Requisition LIKE '" & Trim(requnum) & "%' "
End If
If Trim(postit) <> "" Then
If strFilter <> "" Then
strFilter = strFilter & "AND Full_Name LIKE '" & Trim(postit) & "%'"
Else
strFilter = "Full_Name LIKE '" & Trim(postit) & "%'"
End If
End If
objRs.Filter = strFilter
Set DataGrid1.DataSource = objRs
'显示获得的记录条数
Label4 = "Total Annal: " & objRs.RecordCount
End Sub
Private Sub Form_Load()
Set objCn = New Connection '实例化Connection对象objCn
strcn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\database\Sourcing Tracking Sheet.mdb;" & _
"Persist Security Info=False"
objCn.ConnectionString = strcn '创建数据库连接
objCn.Open
strSQL = "SELECT * FROM Australia_Candidate_Record "
Set objRs.ActiveConnection = objCn
objRs.CursorLocation = adUseClient
objRs.CursorType = adOpenStatic
objRs.Open strSQL
Label4 = "" '清除标签4
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objRs = Nothing
objCn.Close
Set objCn = Nothing
End Sub 展开
希望高手帮我改一下后能实现模糊查询。
关键代码如下:
Dim objRs As New Recordset, objCn As Connection, strFilter$
Private Sub cmdQuery_Click()
If Trim(requnum) = "" Then
strFilter = ""
Else
strFilter = "Requisition LIKE '" & Trim(requnum) & "%' "
End If
If Trim(postit) <> "" Then
If strFilter <> "" Then
strFilter = strFilter & "AND Full_Name LIKE '" & Trim(postit) & "%'"
Else
strFilter = "Full_Name LIKE '" & Trim(postit) & "%'"
End If
End If
objRs.Filter = strFilter
Set DataGrid1.DataSource = objRs
'显示获得的记录条数
Label4 = "Total Annal: " & objRs.RecordCount
End Sub
Private Sub Form_Load()
Set objCn = New Connection '实例化Connection对象objCn
strcn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\database\Sourcing Tracking Sheet.mdb;" & _
"Persist Security Info=False"
objCn.ConnectionString = strcn '创建数据库连接
objCn.Open
strSQL = "SELECT * FROM Australia_Candidate_Record "
Set objRs.ActiveConnection = objCn
objRs.CursorLocation = adUseClient
objRs.CursorType = adOpenStatic
objRs.Open strSQL
Label4 = "" '清除标签4
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objRs = Nothing
objCn.Close
Set objCn = Nothing
End Sub 展开
3个回答
展开全部
通配符%在LIKE句中模糊查询内容前后都用,例:
SQL = "select * from iask where 问题 like'%" & Trim(Text5) & "%'"
SQL = "select * from iask where 问题 like'%" & Trim(Text5) & "%'"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这样也行的
SQL="select * from 数据表 where instr(gao wei," & Text1 & ")>0"
绝对比Like好用
SQL="select * from 数据表 where instr(gao wei," & Text1 & ")>0"
绝对比Like好用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询