In the WINCC graphic editor, select an event from the properties of the input domain, select the release action on the keyboard, and write the following code in the Action Code box: Dimconn, rsDimstrsqlDimaaHMIRuntime. tags (datavariable ). readSetconnCreateObject (adodb. connection) SetrsCreateObje
In the WINCC graphic editor, select an event from the properties of the input domain, select the release action on the keyboard, and write the following code in the Action Code box: Dim conn, rs Dim strsql Dim a = HMIRuntime. tags (datavariable ). read Set conn = CreateObject (adodb. connection) Set rs = CreateObje
WINCC write Database
In the WINCC graphic editor, select an event from the input field attributes, select the release action on the keyboard, and write the following code in the Action Code box:
Dim conn, rs
Dim strsql
Dim
A = HMIRuntime. Tags ("datavariable"). Read
Set conn = CreateObject ("adodb. connection ")
Set rs = CreateObject ("adodb. recordset ")
Conn. Provider = "sqloledb"
Conn. open "SERVER = Yang-PC \ WINCC; uid = sa; pwd = sa; database = datasavetest"
Strsql = "insert into tt_ch (TagValue) VALUES ('" & &"')"
Set rsw.conn.exe cute (strsql)
Conn. close
Set rs = Nothing
Set conn = Nothing
End If
In this way, real-time WINCC data can be written to SQL SERVER.
WINCC read database
Dim conn, rs
Dim strsql
Dim temp1, temp2
Set conn = CreateObject ("adodb. connection ")
Set rs = CreateObject ("adodb. recordset ")
Conn. Provider = "sqloledb"
Conn. open "SERVER = YANG-PC \ WINCC; uid = sa; pwd = 1988525; database = datasavetest"
Strsql = "select * from table_1"
Set rsw.conn.exe cute (strsql)
Rs. movenext can read the next row of the dataset and perform operations using other attributes of the dataset.
Temp1 = rs. Fields (0). value' take the Value of the first column
'Temp1 = rs ("text") Get the value of the field "text" from the dataset
Set temp2 = HMIRuntime. Tags ("textdataAuto ")
Temp2.Read
Temp2.Write temp1
Conn. close
Set rs = Nothing
Set conn = Nothing