请帮忙看下这个哪里有错误

望着天空的人WXW 2020-02-29 12:49:07
Public Sub showbb()
Dim i As Integer
Dim j As String
Dim k As String
Dim X As Date
Dim time1 As String
Dim time2 As String
Dim time3 As String
Dim Y As String
Dim Rs As New ADODB.Recordset '定义连接数据库的ADO变量
time1 = Format(datetime.Value, "yyyy-MM-dd")

X = CDate(time1)
Y = " '" + time1 + "'"
For i = 0 To 23
If i < 10 Then
j = CStr(i)
time2 = "0" & j & ":" & "00" & ":" & "00"
End If
If i >= 10 Then
j = CStr(i)
time2 = j & ":" & "00" & ":" & "00"
End If
If i + 1 < 10 Then
k = CStr(i + 1)
time3 = "0" & k & ":" & "00" & ":" & "00"
End If
If i + 1 >= 10 Then
k = CStr(i + 1)
time3 = k & ":" & "00" & ":" & "00"
End If
openDB1 '打开IFIX_DATA数据库,该函数在后面有定义
CmdTruck.ActiveConnection = conn
CmdTruck.CommandText = "select data.PH,data.PAH,data.浊度 from data where convert(char(10),时间,120)= 'time1'and convert(char(8),时间,108) between 'time2' and 'time3'"
Set Rs = CmdTruck.Execute
这样写查询不到数据,当把time1,time2,time3换成准确值如:time1改成2020-02-28,time2改成14:00:00,time3改成15:00:00时可以查询到数据,请帮忙看看错在哪里?
...全文
48 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧