你打开报警归档的数据库的table 看看各个字段 按照需求读取
这是我写的 读取报警归档之后 将归档值写入内部变量的例子
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim conn
Dim oRs
Dim oCom
Dim oItem
'Dim m,n,s
'connection string
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=CC_GDSmartP_12_03_10_08_18_49R;" '数据库名
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
'sCon="Provider=WinCCOLEDBProvider.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SSEJRecord;Data Source=.\WINCC"
'MsgBox "set sCon"
'sSQL为查询命令
sSql = "ALARMVIEW:Select * FROM AlgViewCht WHERE MsgNr=1"
'sSql = "ALARMVIEW:SELECT * from AlgViewChs"
'MsgBox "Set SQL"
'建立连接
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = 3
conn.Open
'MsgBox "conn Open"
'进行查询
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
'MsgBox "set command"
'填充记录集
Set oRs = oCom.Execute
'm = oRs.Fields.Count
MsgBox oRs.EOF
If(oRs.EOF) Then
oRs.Close
Else
oRs.MoveFirst
Do While Not oRs.EOF
HMIRuntime.Tags("AlarmText1").Write CStr(oRs.Fields(17).Value)
HMIRuntime.Tags("AlarmText2").Write CStr(oRs.Fields(18).Value)
HMIRuntime.Tags("AlarmText3").Write CStr(oRs.Fields(19).Value)
HMIRuntime.Tags("AlarmText4").Write CStr(oRs.Fields(20).Value)
HMIRuntime.Tags("AlarmText5").Write CStr(oRs.Fields(21).Value)
HMIRuntime.Tags("AlarmText6").Write CStr(oRs.Fields(22).Value)
HMIRuntime.Tags("AlarmText7").Write CStr(oRs.Fields(23).Value)
oRs.MoveNext
Loop
oRs.Close
End If
Set oRs = Nothing
conn.Close
Set conn = Nothing