vb中的用时间查询代码怎么编?解决追加100分!!!

来源:百度知道 编辑:UC知道 时间:2024/05/10 23:42:58
我想通过时间进行模糊查询,怎么编他的代码啊?有高手会吗?我用的是SQL Server数据库.

楼主看这个可以用不?
VB都丢了两年了,不是太熟。
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