vb 模糊查询语句的问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:01:32
给看看下列程序:
txtyear.text,txtmonth.text,txtdat.txt 分别填写年,月,日的文本框
dim strSQL as string
If TxtYear.Text = "" Then
MsgBox "请填写统计年份!", vbOKOnly + vbExclamation, "统计分析"
TxtYear.SetFocus
Exit Sub
ElseIf TxtYear.Text <> "" And TxtMonth.Text = "" And TxtDay.Text = "" Then
strSQL = TxtYear.Text
ElseIf TxtYear.Text <> "" And TxtMonth.Text <> "" And TxtDay.Text = "" Then
strSQL = TxtYear.Text & "-" & TxtMonth.Text
ElseIf TxtYear.Text <> "" And TxtMonth.Text <> "" And TxtDay.Text <> "" Then
strSQL = TxtYear.Text & "-" & TxtMonth.Text & "-" & TxtDay.Text
Else
MsgBox "统计时段填写错误,无法进行统计!", vbOKOnly + vbExclamation, "统计分析"
TxtYear.SetFocus
Exit Sub
End If
用的sql server 2000 数据库

思路是没错的。查询这类错误最好把SQL语句打印到屏幕上,这样容易查找错误原因。
另外TxtYear.Text <> "" And TxtMonth.Text <> "" And TxtDay.Text <> "" Then语句中的TEXT文本框最好都加上Trim()函数,去掉两边的空格