vb 模糊查询 快交论文了,谢谢各位了!!
Private Sub Command1_Click()
Dim strQuery As String
Adodc1.CommandType = adCmdText
If Option1.Value = True Then
strQuery = "select * from 论文成果 where 教师姓名='" & Trim(Text3.Text) & "'"
End If
If Option2.Value = True Then
strQuery = "select * from 论文成果 where 论文题目='" & Trim(Text3.Text) & "'"
End If
If Option3.Value = True Then
strQuery = "select * from 论文成果 WHERE 发表时间 BETWEEN #" & DTPicker1.Value & "# AND #" & DTPicker2.Value & "#"
End If
Adodc1.RecordSource = strQuery
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "不存在此记录!"
End If
End Sub
这是我查询的代码,我想把 教师姓名 和 论文题目 查询做成模糊查询,要求不高,比如“赵子贤”输入赵就能查到就行,论文题目也是这样,我改了很多次都不成果,谢谢各位了!!
一下是同学做的一个,把这个套入也行,我的时间查询肯定要精确的,然后教师题目和论文题目模糊查询,再次致谢!!
Private Sub 查询_Click()
Dim SQLstr As String
Dim SQLstr1(3) As String
Dim markSQL(3) As Boolean
Dim i As Integer
markSQL(0) = False
'初始化条件字符串
SQLstr1(1) = " 车牌号 like "
SQLstr1(2) = " 车型 = "
SQLstr1(3) = " 车色 like "
'判断用户输入了哪些信息
If Trim(text1.Text) <> "" Then
SQLstr1(1) = SQLstr1(1) & "'%" & Trim(text1.Text) & "%'"
markSQL(1) = True
markSQL(0) = True
End If
If Combo1.ListIndex <> 4 Then
SQLstr1(2) = SQLstr1(2) & "'" & Combo1.Text & "'"
markSQL(2) = True
markSQL(0) = True
End If
If Trim(text2.Text) <> "" Then
SQLstr1(3) = SQLstr1(3) & "'%" & Trim(text2.Text) & "%'"
markSQL(3) = True
markSQL(0) = True
End If
SQLstr = "select * from 车辆档案 "
'判断第一个筛选信息是哪一个
If markSQL(0) = True Then
i = 1
While markSQL(i) <> True
i = i + 1
Wend
SQLstr = SQLstr & " where " & SQLstr1(i)
End If
'填写sql语句
If i < 3 Then
For i = i + 1 To 3
If markSQL(i) = True Then
SQLstr = SQLstr & " and " & SQLstr1(i)
End If
Next i
End If
Adodc1.RecordSource = SQLstr
Adodc1.Refresh
Adodc1.Refresh
End Sub
[解决办法]
看这:http://iask.sina.com.cn/b/1758202.html
[解决办法]
strQuery = "select * from 论文成果 where 教师姓名 Like '%" & Trim(Text3.Text) & "%'"