非常简单
程序代码:
Private Sub Form_Load()
Dim db As New ADODB.Connection, RS As New ADODB.Recordset
Dim SST As Integer, SID() As Long, TT1() As Single, TT2() As Single, TT3() As Single, Tmax1() As Single, Tmax2() As Single, Tmax3() As Single, K As Integer '声明变量与数组变量
db.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\T1数据库.accdb;Jet OLEDB:Database Password=;"
db.Open '连接数据库
RS.Open "Select distinct stationID From T1数据表", db, 3, 2 '得到 stationID 字段不重复记录,distinct 是关键字
SST = RS.RecordCount
ReDim SID(1 To SST), TT1(1 To SST), TT2(1 To SST), TT3(1 To SST), Tmax1(1 To SST), Tmax2(1 To SST), Tmax3(1 To SST) '声明动态数组变量的下标
Do While Not RS.EOF
K = K + 1
SID(K) = RS!stationID '取得不重复的 stationID 记录存储在 SID 数组
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
For I = 1 To SST '循环,得到需要的数据
RS.Open "Select * From T1数据表 Where stationID=" & SID(I) & "", db, 3, 2
Do While Not RS.EOF
If RS!obsdatatime = "2017-06-12 08:00:00.000" Then TT1(I) = RS!TT: Tmax1(I) = RS!Tmax '如果 obsdatatime 的记录是 "2017-06-12 08:00:00.000",分别存储在 TT1 与 Tmax1 的数组中
If RS!obsdatatime = "2017-06-12 07:00:00.000" Then TT2(I) = RS!TT: Tmax2(I) = RS!Tmax '如果 obsdatatime 的记录是 "2017-06-12 07:00:00.000",分别存储在 TT2 与 Tmax2 的数组中
If RS!obsdatatime = "2017-06-12 06:00:00.000" Then TT3(I) = RS!TT: Tmax3(I) = RS!Tmax '如果 obsdatatime 的记录是 "2017-06-12 06:00:00.000",分别存储在 TT3 与 Tmax3 的数组中
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
Next I
db.Close '关闭数据库
Set db = Nothing
MSHFlexGrid1.Clear
MSHFlexGrid1.Visible = True
With MSHFlexGrid1
.Cols = 7
.Rows = 1 + SST
.TextMatrix(0, 0) = "stationID"
.TextMatrix(0, 1) = "TT1"
.TextMatrix(0, 2) = "TT2"
.TextMatrix(0, 3) = "TT3"
.TextMatrix(0, 4) = "Tmax1"
.TextMatrix(0, 5) = "Tmax2"
.TextMatrix(0, 6) = "Tmax3"
.ColWidth(0) = 1300
.ColWidth(1) = 800
.ColWidth(2) = 800
.ColWidth(3) = 800
.ColWidth(4) = 1000
.ColWidth(5) = 1000
.ColWidth(6) = 1000
For I = 1 To SST '在 MSHFlexGrid1 控件显示记录
.TextMatrix(I, 0) = SID(I)
.TextMatrix(I, 1) = Format(TT1(I), "0.0")
.TextMatrix(I, 2) = Format(TT2(I), "0.0")
.TextMatrix(I, 3) = Format(TT3(I), "0.0")
.TextMatrix(I, 4) = Format(Tmax1(I), "0.0")
.TextMatrix(I, 5) = Format(Tmax2(I), "0.0")
.TextMatrix(I, 6) = Format(Tmax3(I), "0.0")
Next I
End With
End Sub
是不是特简单?这个是使用Access数据库与VB实现的,不是ASP+SQL数据库,稍稍修改一下就可以了。
[此贴子已经被作者于2017-7-9 11:30编辑过]