vb时间段查询这句有错吗?

来源:百度知道 编辑:UC知道 时间:2024/07/08 12:56:21
Adodc1.RecordSource = "select * from 班次 where 日期 between '" & Format$(text1.Text, "yyyy-mm-dd") & "' and '" & Format$(text2.Text, "yyyy-mm-dd") & "'"
这个写在同一行,没有分行 ,有错的话能不能把你的结果完整的写下来我去试试?
text1.Text = Format(text1.Text, "YYYY-MM-DD")
text2.Text = Format(text2.Text, "YYYY-MM-DD")
Adodc1.RecordSource = "select * from 班次 where 日期 between #text1.text# and #text2.text#"
这样写哪里出错了? text里的内容是日期啊,比如2008-08-08
我在数据库里用select * from 班次 where 日期 between #1989-1-1# and #1999-1-1#这句查询是对的。放VB里就说是FROM子语句错误。

dim sql as string
text1.Text = Format(text1.Text, "YYYY-MM-DD")
text2.Text = Format(text2.Text, "YYYY-MM-DD")
if isdate(text1.Text) and isdate(text2.Text) then
sql="select * from 班次 where 日期 between #"& cdate(text1.text) &"# and #"& cdate(text2.text) &"#"
debug.print sql '调试加上这句,按Crtl+G打开立即窗口,看看SQL语句对不对
Adodc1.RecordSource = sql
else
msgbox "输入的日期格式不正确"
end if

好像是没错的.

text1.Text和text2.Tex的内容是什么
如果是"200090812"之类的那就有错了,
format不用这么用的
应该是format$(text1.Text, "0000-00-00")

Adodc1.RecordSource = "select * from 班次 where 日期 between #" &text1.Text & "# and #" & text2.Text & "#" 直接这么写就可以,只是在文本框里输入的时候要按YYYY-MM-DD格式输入,不然就会出错