大侠们,为什么我在读取wincc归档数据的时候不能在listview中显示新归档的数据啊,只是显示老的数据,我采用的是相对时间查询的,数据库里面的数据肯定更新了,从其他程序里面可以看到
代码如下:
Dim sPro, sDsn, sSer,sCon, sSql
Dim sVid, sVal, lRet, sRel
Dim V,Sum,Avg,Std
Dim conn, oRs, oCom, oList, oItem
Dim m,n,s,nRec
Dim strDateTime, iMs ,jMs
' 0.0 Get parameters from picture
sDsn = ScreenItems("laDSN").Text
sSer = ScreenItems("laServer").Text
sSql = ScreenItems("laSql").Text
' 1.1 Make connection string for ADODB as indicated below
'"Provider=WinCCOLEDBProvider.1;Catalog=CC_V6_Demo3_03_02_04_16_19_15R;Data Source=.\WinCC"
' 1.2 Define command text in sSql for WinCC compressed archives, relative time
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=" + sDsn + ";"
sSer = "Data Source=" + sSer + "\WinCC"
sCon = sPro + sDsn + sSer
nRec = NMAX
' "TAG:R,1,'0000-00-00 00:05:00.000','0000-00-00 00:00:00.000'"
lRet = MsgBox("Opened with " & vbCr & sCon & vbCr & sSql & vbCr, vbOKCancel)
If lRet <> 1 Then Exit Sub
' 2.1 Make connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = adUseClient ' 3
conn.Open
' 2.2 Use command text for query
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1 ' adCmdText = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
'2.3 Fill the recordset
Set oRs = oCom.Execute
m = oRs.Fields.Count
' 3.0 Fill standard listview object with recordset
Set oList = ScreenItems("ListTable")
oList.ListItems.Clear
If(m>0) Then
oRs.MoveFirst
If( n < nRec ) Then
SplitDateTimeAndMs oRS.Fields(1).Value, strDateTime, iMs
s = FormatDateTime(strDateTime,2) & " " & FormatDateTime(strDateTime,3)
Set oItem = oList.ListItems.Add()
oItem.Text = s + "."+iMs
Select Case FormatNumber(V, 4)
Case 10.0000
oItem.SubItems(1) = "门禁故障解除"
Case Else
oItem.SubItems(1) = "错误信息"
End Select
End If
oRs.MoveNext
Loop
oRs.close
End If
Set oRs = Nothing
conn.Close
Set conn = Nothing
Set oCom = Nothing