mariadb 在MySql数据库中搜索两个日期

92dk7w1h  于 2023-04-20  发布在  Mysql
关注(0)|答案(2)|浏览(121)

我有一个问题,使一个SQL查询在vb 6使用MySQL数据库.基本上,我试图做的是从MySQL数据库检索数据到列表视图.虽然同样的代码是完美的工作与Access数据库.
我写的错误来:
[MySQL][ODBC 5.1 Driver] [mysql-5.5.5-10.4.28-MariaDB]您的SQL语法中有错误;查看与您的MariaDB Server版本对应的手册,以了解在第1行“附近使用的正确语法

Dim list As List Item
ListView1.ListItems. Clear
Dim date1 As Date
Dim date2 As Date
date1 = Me. DTPicker1.Value, "mm/dd/yyyy")
date2 = Me. DTPicker2.Value, "mm/dd/yyyy")
If mysqlcn.State = adStateOpen Then mysqlcn.Close

Do Events
Set mysqlcn = New ADODB.Connection
With mysqlcn
.ConnectionString = "Driver= {MySQL ODBC 5.1 Driver};"
& "Server=localhost;"
& "Database=db_test;"
& "User=root;"
& "Password=;"
& "Option=3;"
.CursorLocation = adUseClient
. Open
End With
Rs. Open "Select* from register where Date0 between # " & date1 & " #  AND # " & date2 & " #", mysqlcn,        adOpenDynamic, adLockPessimistic
Do Until rs.EOF
Set list = ListView1.ListItems. Add(, , rs!ID)
list.SubItems(1) = rs!Date0
list.SubItems(2) = rs!CashStatus
list.SubItems(3) = rs!TrxId
list.SubItems(4) = rs!To
list.SubItems(5) = rs!AccountNo
list.SubItems(6) = rs!Amount
list.SubItems(7) = rs!AccountTitle
list.SubItems(8) = rs!From
list.SubItems(9) = rs!PrintedBy
list.SubItems(10) = rs!Comission
rs.MoveNext
Loop
rs.Close
ux6nzvsh

ux6nzvsh1#

Rs.Open "Select * from register where Date0 between '" & _
        Format(date1, "yyyy-mm-dd") & "' AND '" & _
        Format(date2, "yyyy-mm-dd") & "'", _
        mysqlcn, adOpenDynamic, adLockPessimistic
ddhy6vgd

ddhy6vgd2#

你的查询中的#告诉mysql从这里开始的所有内容都是注解,所以你的查询以“between“结束。删除它们。

相关问题