VB实现模糊查询

来源:百度知道 编辑:UC知道 时间:2024/05/22 10:39:30
Private Sub Command1_Click()
Set rsrecordset2 = New ADODB.Recordset
rsrecordset2.ActiveConnection = connconnection
strcon = "select * from 名单 where "
strtext = Text1.Text
strque = strcon & "详细名称='" & strtext & "'"
If Text1.Text = "" Then
MsgBox "请输入详细名称!", vbExclamation
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
rsrecordset2.Source = strque
rsrecordset2.Open
If rsrecordset2.RecordCount = 0 Then
MsgBox "没有找到要查询的信息", vbOKOnly
End If
Call bind1

End Sub

strque = strcon & "详细名称='" & strtext & "'"
修改为:
strque = strcon & "详细名称 like '%" & strtext & "%'"

1。连接SQL server数据库是:
strque = strcon & "详细名称 like '%" & strtext & "%'"
2。连接ACCESS数据库是
strque = strcon & "详细名称 like '*" & strtext & "*'"
我就用过这两个数据库

strque = strcon & " 详细名称='%" & strtext & "%'"

strque = strcon & "详细名称 like '%" & strtext & "%'"

是对的