Vb+access2000,怎么进行模糊查询?sql语句怎么写?
我写的好像不对,星号间的部分,请教各位大哥,谢了先!Private Sub Command1_Click()
On Error GoTo err1
t1 = Trim(Text1.Text)
Dim x As Integer
*********************************************************************************
If InStr(Text1.Text, "*") Or InStr(Text1.Text, "?") Then '模糊查询
MsgBox "模糊查询"
With shiprec
.Open "SELECT * FROM 记录参数 where (shipname like'" & t1 & "')", ship, adOpenStatic, adLockOptimistic
' 移动到记录尾部获得记录号,然后返回,以便获得总记录数。
.MoveLast
.MoveFirst
***********************************************************************************
End With
With shiprec
If .RecordCount > 1 Then
x = .RecordCount
MsgBox "含有名字" & t1 & "的记录共有" & x & "条", vbOKOnly, "信息"
Else
MsgBox "存在记录,请选择您需要的资料!", vbOKOnly, "信息"
End If
End With
Else
不含*和?时的精确查询部分省略了
End If
shiprec.Close
Set shiprec = Nothing
Command3.Enabled = True
Unload Me
frmresult.Show
Exit Sub
err1: MsgBox "没有记录,请确认名字是否正确!", vbOKOnly, "信息"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
我写的好像不对,星号间的部分,请教各位大哥,谢了先!Private Sub Command1_Click()
On Error GoTo err1
t1 = Trim(Text1.Text)
Dim x As Integer
*********************************************************************************
If InStr(Text1.Text, "*") Or InStr(Text1.Text, "?") Then '模糊查询
MsgBox "模糊查询"
With shiprec
.Open "SELECT * FROM 记录参数 where (shipname like'" & t1 & "')", ship, adOpenStatic, adLockOptimistic
' 移动到记录尾部获得记录号,然后返回,以便获得总记录数。
.MoveLast
.MoveFirst
***********************************************************************************
End With
With shiprec
If .RecordCount > 1 Then
x = .RecordCount
MsgBox "含有名字" & t1 & "的记录共有" & x & "条", vbOKOnly, "信息"
Else
MsgBox "存在记录,请选择您需要的资料!", vbOKOnly, "信息"
End If
End With
Else
不含*和?时的精确查询部分省略了
End If
shiprec.Close
Set shiprec = Nothing
Command3.Enabled = True
Unload Me
frmresult.Show
Exit Sub
err1: MsgBox "没有记录,请确认名字是否正确!", vbOKOnly, "信息"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
所以不知道
myhgyp(也许是这样的,信不信由你)你的方法可不可行?
谢谢
.find("xxx like '" & 你要查询的内容 & "'")如果是sql语句的话就是直接里面select xxx from xx where xxx like xxx,注意where后面的条件如果是字符的话要用单引号括起来。
t1 = Trim(Text1.Text),