Dim ConnectionObj
Dim Connectionstring
Dim StrConn
Dim CommandObj
Dim CommandObj2
Dim RecordSetObj
Dim tsagDSNName
Dim MsgNo,State,Time2,Text
Set tsagDSNName=HMIRuntime.Tags("@DatasourceNameRT")
tsagDSNName.Read
Connectionstring="Provider=WinCCOLEDBProvider.1;Catalog="&tsagDSNName.Value&";Data Source=.\WinCC"
Set ConnectionObj=CreateObject("ADODB.Connection")
ConnectionObj.ConnectionString=Connectionstring
ConnectionObj.CursorLocation=3
ConnectionObj.Open
Set RecordSetObj=CreateObject("ADODB.Recordset")
Set CommandObj=CreateObject("ADODB.Command")
Set CommandObj.ActiveConnection=ConnectionObj
CommandObj.CommandType=1
CommandObj.CommandText="AlARMVIEW:SELECT * from ALGVIEWCHT"
Set RecordSetObj=CommandObj.Execute
If RecordSetObj.EOF Then
MsgBox "no data found or data has not archived!",,"Error"
RecordSetObj.Close
Set RecordSetObj=Nothing
Set CommandObj=Nothing
ConnectionObj.Close
Set ConnectionObj=Nothing
Else
RecordSetObj.MoveFirst
MsgNo=RecordSetObj.Fields(1).Value
RecordSetObj.MoveLast
State=RecordSetObj.Fields(2).Value
RecordSetObj.MoveLast
Time2=RecordSetObj.Fields(3).Value
RecordSetObj.MoveLast
Text=RecordSetObj.Fields(38).Value
Set StrConn=CreateObject("ADODB.Connection")
StrConn.ConnectionString="Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;UserID=sa;Initial Catalog=system_manage;Data Source=.\Wincc"
StrConn.Open
Set CommandObj2=CreateObject("ADODB.Command")
Set CommandObj2.ActiveConnection=StrConn
CommandObj2.CommandType=1
CommandObj2.CommandText="insert into abc(bh,zt,rq,wb)values('" + MsgNo+ "','" + State + "','" + Time2+ "','" + Text + "',)"
Set RecordSetObj=CommandObj.Execute
RecordSetObj.Close
Set RecordSetObj=Nothing
Set CommandObj=Nothing
Set CommandObj2=Nothing
ConnectionObj.Close
Set ConnectionObj=Nothing
StrConn.Close
Set StrConn=Nothing
End If