wincc7.0用VBS连SQL数据库

已锁定

小建子

  • 帖子

    29
  • 精华

    0
  • 被关注

    1

论坛等级:游民

注册时间:2015-02-17

普通 普通 如何晋级?

wincc7.0用VBS连SQL数据库

839

3

2015-03-27 17:11:54

请 大神们帮我看看把wincc变量的值通过按钮的脚本事件存入SQL数据库,从SQL数据库取出数据并显示在wincc控件中的代码,先谢过各位
写数据到数据库的代码如下:
Sub OnClick(ByVal Item)
Dim objConnection
Dim strConnectionString
Dim onjRecordset
Dim objCommand
Dim lngValue
Dim strSQL

strconnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & yejian.Value &";Data Source=.\WINCC"

lngValue=HMIRuntime.Tags("Tag1").Read

Set objConnection=CreateObject("ADODB.Connection")

objConnection.ConnectionString=strConnectionString

objConnection.CursorLocation=3

objConnection.Open

strSQL="INSERT INTO WINCC_DATA(TagValue) VALUES(" & lngValue &");"

Set objRecordset=CreateObject("ADODB.Recordset")

Set objCommand=CreateObject("ADODB.Command")

objCommand.CommandType=1

Set objCommand.ActiveConnection=objConnection

objCommand.CommandText=strSQL

Set objRecordset=Nothing

objConnection.Close

Set objConnection=Nothing

End Sub


读数据到wincc控件的代码:
Sub OnClick(ByVal Item)
Dim objConnection

Dim objCommand

Dim objRecordset

Dim strConnectionString

Dim strSQL

Dim lngValue

strConnectionString = "Provider=SQLOLEDE.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & yejian.Value & ";Data Source=.\WINCC"

Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.CursorLocation=3

objConnection.Open

strSQL = "select TagValue from WINCC_DATA where ID = 1"

Set objRecordset = CreateObject("ADODB.Recordset")

Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection

objCommand.CommandType=1

objCommand.CommandText = strSQL

Set objRecordset = objCommand.Execute

lngValue = objRecordset.Fields(0).Value

HMIRuntime.Tags("dbValue").Write lngValue

Set objCommand = Nothing

objConnection.Close

Set objRecordset = Nothing

Set objConnection = Nothing

End Sub
wincc7.0用VBS连SQL数据库 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32914条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。