您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页机房收费系统之—怎样查询两个日期之间的数据

机房收费系统之—怎样查询两个日期之间的数据

来源:爱玩科技网


日历控件刚刚学会怎么弄,但是要查询这两个语句之间的数据的语法我可是较劲脑汁啊,在网上查,自己试,可是每次不是语法错误就是连接不上数据库,我感觉这个方法就在我的眼前,我就是弄不出来,煞费苦心

日历控件刚刚学会怎么弄,但是要查询这两个语句之间的数据的语法我可是较劲脑汁啊,在网上查,自己试,可是每次不是语法错误就是连接不上数据库,我感觉这个方法就在我的眼前,我就是弄不出来,煞费苦心啊。下面是查询两个日历控件之间的代码,大家可以看看。

Private Sub Command1_Click()
 date1 = DTPicker1.Value‘这是日历控件
 date2 = DTPicker2.Value
 '比较两个日期的大小
 If DateDiff("n", CDate(date1), CDate(date2)) < 0 Then
 MsgBox "起始日期与结束日期有冲突,请重新选择日期", , "提示"
 Exit Sub
 End If
 txtSQL = "select * from Recharge_Info where date >='" & date1 & "' and date <='" & date2 & "'"
 Set mrc = ExecuteSQL(txtSQL, Msgtext)
 If mrc.EOF = True Then
 MsgBox "没有信息"
 Exit Sub
 End If
 With MSFlexGrid1
 
 Do While mrc.EOF = False
 .CellAlignment = 4
 .Rows = .Rows + 1
 .TextMatrix(.Rows - 2, 0) = mrc!cardno
 .TextMatrix(.Rows - 2, 1) = mrc!addmoney
 .TextMatrix(.Rows - 2, 2) = mrc!Date
 .TextMatrix(.Rows - 2, 3) = mrc!Time
 .TextMatrix(.Rows - 2, 4) = mrc!userID
 .TextMatrix(.Rows - 2, 5) = mrc!Status
 mrc.MoveNext
 If mrc.EOF = True Then
 .Rows = .Rows - 1
 End If
 Loop
 End With
 mrc.Close
End sub

写了一大堆,其实最有用的是这句话
txtSQL = "select * from Recharge_Info where date >='" & date1 & "' and date <='" & date2 & "'"
此方法不仅可以比较日期,以此类推,基本上带数字的都能比较吧!

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务