调用access中一列数据进行计算 并将结果显示到MSHFlexGrid中
access中有一列数据是时间比如2017-6-5,怎么调用这列数据减去当前时间得到天数,显示在MSHFlexGrid中。
非常简单,关键代码如下,数据库连接略。
程序代码:
Dim db As New ADODB.Connection, cors As New ADODB.Recordset '------------------------------------------------------------- cors.Open "select * from 日期数据 ", db, 3, 2 AAA = cors.RecordCount MSFlexGrid1.Clear MSFlexGrid1.Visible = True With MSFlexGrid1 .Cols = 4 .Rows = 1 + AAA .TextMatrix(0, 0) = "序号" .TextMatrix(0, 1) = "日期" .TextMatrix(0, 2) = "今日日期" .TextMatrix(0, 3) = "间隔天数" '8295 .ColWidth(0) = 800 .ColWidth(1) = 1500 .ColWidth(2) = 1500 .ColWidth(3) = 1500 For I = 1 To AAA .TextMatrix(I, 0) = I .TextMatrix(I, 1) = cors!日期 .TextMatrix(I, 2) = Date .TextMatrix(I, 3) = DateDiff("d", cors!日期, Date) cors.MoveNext Next I End With