WINCC 脚本里面读写的2005 SQL数据库表格数据到WINCC变量显示,就是不能成功?
也是看网上VBS做的,没有报错,但就是不能读写.目的要根据WINCC IO域输入的ID查询符合条件的5个字段值.哪位有例程?
问题补充:
Dim conn,rs
Dim strsql
Dim a
a=HMIRuntime.Tags("station_number").Read
Set conn=CreateObject("adodb.connection")
Set rs=CreateObject("adodb.recordset")
conn.Provider = "sqloledb"
conn.open "SERVER=WINCC;uid='';pwd='';database=hotpower"
If nChar = "13" Then
strsql="insert into dbo.station_info(station_number)VALUES('"&a&"')"
Set rs=conn.execute(strsql)
conn.close
Set rs=Nothing
Set conn=Nothing
End If
这个程序问题在哪里?在键盘释放动作触发
最佳答案
Dim objConnection
Dim strConnectionString
Dim strSQL
Dim objCommand
If nChar = "13" Then
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='数据库名';Data Source=MICROSOF-3B11D2\WINCC"
strSQL = "INSERT INTO dbo.station_info(station_number) VALUES('"&a.value&"')"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End If
提问者对于答案的评价:
谢谢了
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc266556.html