Dim rmfrom As Date
rmfrom = DateTime.ParseExact(hapfromrm.Value, "dd/mm/yyyy", Nothing)
Dim rmto As Date
rmto = DateTime.ParseExact(hapfromrm.Value, "dd/mm/yyyy", Nothing)
con.Open()
cmd = New OleDbCommand("SELECT * FROM writes WHERE date_written BETWEEN " & rmfrom & " AND " & rmto & "", con)
它给了我以下错误:
查询表达式' date_written中的语法错误(缺少运算符) BETWEEN 1/2/2015 12:11:00 AM和1/2/2015 12:11:00 AM'。
解决方法是什么? 任何帮助将不胜感激。
答案 0 :(得分:0)
您需要为日期添加格式正确的字符串表达式:
cmd = New OleDbCommand("SELECT * FROM writes WHERE date_written BETWEEN #" & rmfrom.ToString("yyyy'/'MM'/'dd") & "# AND #" & rmto.ToString("yyyy'/'MM'/'dd") & "#", con)