现在用WINCC6.2,SQL2005。在WINCC6.2中用VB脚本实现以下数据写入:
Dim conn,rs
Dim biaozhi
biaozhi = HMIRuntime.Tags("2").Read
Set conn = CreateObje("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
conn.open "Provider=MSDASQL;DSN=student;UID=;PWD=;"
rs.open "select * from JILU",conn,3,3
rs.addnew
rs.fields("时间")=Now
rs.fields("号")= biaozhi
rs.fieldS("量")=FormatNumbe(HMIRuntime.Tags("1量").Read,2)
rs.update
rs.cLose
Set rs = Nothing
conn.cloSe
Set conn = Nothing
这个脚本在WINCC6.0,SQL2000中可以实现把数据写入数据库中的表,为什么在WINCC6.2,SQL2005中不行?(各种设置一样,就是WINCC版本和数据库版本不同)
问题补充:
我是在WINCC新建的的项目和脚本,数据库是在SQL2000中建的数据库,然后移植到SQL2005中的
最佳答案
以下我在插入到2005是可以的,你感兴趣测试一下。
Option Explicit
Function action
Dim objConnection
Dim strConnectionString
Dim strSQL
Dim objCommand
Dim objRecordSet
Dim RecordCount
Dim DeviceName
On Error Resume Next
Dim data(5)
Dim i
For i = 0 To 4
data(i) = "Null"
Next
DeviceName=CStr("1#设备运行状态测试")
Data(1)=HMIRuntime.tags("Ractor/Motor1.AUT_ON_OP").read
Data(2)=HMIRuntime.tags("Ractor/Motor1.QRUN").read
If Data(1)="1" Then
Data(1)="远程"
End If
If Data(1)="0" Then
Data(1)="就地"
End If
If Data(2)="1" Then
Data(2)="启动"
'MsgBox Data(2)
End If
If Data(2)="0" Then
Data(2)="停止"
'MsgBox Data(2)
End If
'MsgBox Date()&" "&Time()
'MsgBox Data(1)
'MsgBox Data(2)
''''Continute to insert data to database
data(0) ="Insert into Device_record(DeviceName,DeviceTime,DeviceStatus,DeviceMode)values('"& DeviceName &"','"& Date() &" "& Time() &"','"& data(2) &"','"& data(1) &"')"
'MsgBox data(0)
strConnectionString = "Provider=MSDASQL;DSN=ZJG_DevDSN;UID=sa;PWD=;"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = data(0)
'debug.print objConnection.execute(data(0))
End With
'MsgBox"ok"
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
For i = 0 To 4
data(i) = "Null"
Next
End Function
提问者对于答案的评价:
我试试看看。谢谢啊
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc273382.html