Home > Database > Mysql Tutorial > Wincc操作数据库SQLSERVER

Wincc操作数据库SQLSERVER

PHPz
Release: 2018-09-30 11:06:50
forward
3697 people have browsed it

WINCC写数据库

在WINCC的图形编辑器中,在输入域的属性中。选择事件。再选择键盘的释放动作,在动作代码框中写下例如以下代码:

Dim conn,rs
Dim strsql
Dim a
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('" & a &"')"
   Set rs=conn.execute(strsql)

   conn.close
   Set rs=Nothing

   Set conn=Nothing     

End If

如此,就可以实现WINCC的实时数据向SQL SERVER的数据写入。

WINCC读数据库

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 rs=conn.execute(strsql) 
    rs.movenext'读取数据集中的下一条还能够通过数据集的其它属性进行操作  

temp1 = rs.Fields(0).Value '取第一列的值

'temp1 = rs("text")从数据集中取字段“text”的值

Set temp2 = HMIRuntime.Tags("textdataAuto")
temp2.Read
temp2.Write temp1

conn.close
Set rs = Nothing
Set conn=Nothing 

假设我们须要连接的是access数据库,仅仅须要将

"SERVER=YANG-PC\WINCC;uid=sa;pwd=1988525;database=datasavetest"
Copy after login

替换为

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=datasavetest"
Copy after login

更多相关教程请访问 MySQL视频教程

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template