wincc中使用VBS脚本读写SQLServer数据库文件.doc

上传人:wj 文档编号:2118732 上传时间:2023-05-02 格式:DOC 页数:3 大小:16.50KB
下载 相关 举报
wincc中使用VBS脚本读写SQLServer数据库文件.doc_第1页
第1页 / 共3页
wincc中使用VBS脚本读写SQLServer数据库文件.doc_第2页
第2页 / 共3页
wincc中使用VBS脚本读写SQLServer数据库文件.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

wincc中使用VBS脚本读写SQLServer数据库文件.doc

《wincc中使用VBS脚本读写SQLServer数据库文件.doc》由会员分享,可在线阅读,更多相关《wincc中使用VBS脚本读写SQLServer数据库文件.doc(3页珍藏版)》请在冰点文库上搜索。

wincc中使用VBS脚本读写SQLServer数据库文件.doc

Wincc读写SQLServer数据库

一、在数据库中建立数据库文件,文件名为“读写数据库”,在数据库中建立新的表,命名为“个人信息”分别建立编号、姓名、年龄。

二、数据库中建立表后,在wincc中建立与数据库中类型相同的变量,变量类型相同在读写数据时很重要。

在图形编辑器中新建画面,并在画面中增加三个输入输出域,并连接变量。

三、添加两个按钮控件,分别命名为写数据、读数据

1、在写数据按钮中写入一下VBS脚本

wincc变量写入数据库

定义变量

DimsCon

DimsSql

DimoRs

Dimconn

DimoCom

DimCon

DimData1,Data2,Data3

‘读取wincc变量

Data1=HMIRuntime.tags("编号").read

Data2=HMIRuntime.tags("姓名").read

Data3=HMIRuntime.tags("年龄").read

‘连接数据库

Con="Provider=SQLOLEDB.1;IntegratedSecurity=SSPI;PersistSecurityInfo=False;InitialCatalog=读写数据库;DataSource=.\WINCC"

Setconn=CreateObject("ADODB.Connection")

conn.ConnectionString=Con

conn.CursorLocation=3

conn.Open

‘写入数据库

sSql="insertinto个人信息VALUES('"&Data1&"','"&Data2&"','"&Data3&"');"

SetoRs=CreateObject("ADODB.Recordset")

SetoCom=CreateObject("ADODB.Command")

SetoCom.ActiveConnection=conn

oCom.CommandType=1

oCom.CommandText=sSql

SetoRs=oCom.Execute

SetoRs=Nothing

conn.Close

Setconn=Nothing

在实际项目中需要修改的只有定义变量时增加或减少数据data的个数,Data1=HMIRuntime.tags("编号").read中的变量名,数据库的名字,以及数据库的表名

2、在读数据按钮中写入一下VBS脚本

读取数据库变量到wincc变量

定义变量

DimsCon

DimsSql

DimoRs

Dimconn

DimoCom

DimCon

DimData1

DimData2

DimData3

Dimdata4

Dimdata5

Dimdata6

Dimdata7

data7=HMIRuntime.tags("编号").read

Con="Provider=SQLOLEDB.1;IntegratedSecurity=SSPI;PersistSecurityInfo=False;InitialCatalog=读写数据库;DataSource=.\WINCC"

Setconn=CreateObject("ADODB.Connection")

conn.ConnectionString=Con

conn.CursorLocation=3

conn.Open

sSql="SELECT*FROM个人信息WHERE编号='"&data7&"';"

SetoRs=CreateObject("ADODB.Recordset")

SetoCom=CreateObject("ADODB.Command")

SetoCom.ActiveConnection=conn

oCom.CommandType=1

oCom.CommandText=sSql

SetoRs=oCom.Execute

'SetoRs=Nothing

data4=oRs.Fields(0).Value

data5=oRs.Fields

(1).Value

data6=oRs.Fields

(2).Value

'data1.writedata4

Setdata1=HMIRuntime.Tags("编号")

Setdata2=HMIRuntime.Tags("姓名")

Setdata3=HMIRuntime.Tags("年龄")

data1.Read

data1.Writedata4

data2.Read

data2.Writedata5

data3.Read

data3.Writedata6

SetoRs=Nothing

conn.Close

Setconn=Nothing

读取数据时,按照编号读取数据,在实际中需要修改数据库语言。

运行wincc,再编号输入输出域中输入编号,点击读数据按钮,得到需要的数据

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2