加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【机房收费系统】如何查询固定时间段内的数据MSHflexGrid

发布时间:2020-12-15 03:39:32 所属栏目:百科 来源:网络整理
导读:? ? ? ? ? ? ? ? 在做机房的时候遇到查询时间段的问题,起初的时候就感觉无从下手,后来想了起来,耿建玲老师的视频里讲过两个范围之间的查询,于是就翻翻笔记,问题就解决了,下面把代码贴出来。 ? ? ? ? ? ? ? ? ?? Private Sub Command1_Click() Dim txtS

? ? ? ? ? ? ? ? 在做机房的时候遇到查询时间段的问题,起初的时候就感觉无从下手,后来想了起来,耿建玲老师的视频里讲过两个范围之间的查询,于是就翻翻笔记,问题就解决了,下面把代码贴出来。

? ? ? ? ? ? ? ? ??

Private Sub Command1_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset

If DTPicker1.Value > DTPicker2.Value Then‘当前选中的时间
? ?MsgBox "起始日期不能比终止日期早!",vbOKOnly + vbExclamation,"提示!"
? ?DTPicker1.SetFocus
? ?With MSHFlexGrid1’清空控件内容
? ? ? ? .Col = 2
? ? ? ? .Rows = 1
? ? ? ? .Text = ""
? ? ? ? End With
? ? Exit Sub
End If
? ?With MSHFlexGrid1
? ? ? ? ?.Rows = 2
? ? ? ? ?.CellAlignment = 4
? ? ? ? ?.TextMatrix(1,0) = "卡号"
? ??
? ? txtSQL = "select * from ReCharge_Info where ?date between '" & DTPicker1.Value & " ' and '" & DTPicker2.Value & "'" ?’查询选取时间段的数据
? ? Set mrc = ExecuteSQL(txtSQL,MsgText)
? ? ? ? ? ? ? ? ?If mrc.EOF = True Then?‘该段没有符合的条件
? ? ? ? ? ? ? ? ? ? MsgBox "对不起,该时期没有充值记录!","提示"
? ? ? ? ? ? ? ? ? ? Exit Sub
? ? ? ? ? ? ? ? ?End If
??
? ? ? ? ? ? ? ? ? ? ? ?Do While mrc.EOF = False
? ? ? ? ? ? ? ? ? ? ? ?.Rows = .Rows + 1
? ? ? ? ? ? ? ? ? ? ? ?.CellAlignment = 4
? ? ? ? ? ? ? ? ? ? ? ?.TextMatrix(.Rows - 1,0) = mrc.Fields(2)
? ? ? ? ? ? ? ? ? ? ? ?mrc.MoveNext
? ? ? ? ? ? ? ? ? ? ? ?Loop
? ? ? ? ? ? ? ? ? ? ? ?mrc.Close? ? ? ? ? ? ? ? ??
End With
End Sub
? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? 这整个过程需要格外注意三点:1是 DTPicker1.Value表示当前选中的日期。2是MSHFlexGrid控件的清除,这里参考了李红同学的博客。3就是最重要的Select 字句的查询:Select * from 【表】where 【查询字段】between ‘’and ‘’

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读