最近刚刚接触WINCC 跟着网上教学 做的,现在 WINCC控制PLC正常 就是往数据库写数据时报错,我也搞不定是配置数据库问题,还是代码问题,大佬帮忙看看 !
Option Explicit
Function action
Dim Number,StartTime,StopTime,RunTime
Dim rep
rep=HMIRuntime.Tags("SQL_Pump1_Rep").Read
If rep=1 Then
Number="1#水泵"
StartTime=HMIRuntime.Tags("SQL_Pump1_StartTime").Read
StopTime=HMIRuntime.Tags("SQL_Pump1_StopTime").Read
RunTime=HMIRuntime.Tags("SQL_Pump1_Running").Read
Dim sCon,conn,oRs,sSql,oCom
sCon="SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=wang;Initial Catalog=pump;Data Source=BXDPC\WINCC"
sSql="insert into BB1(编号,启动时间,停止时间,运行时间)values('"&Number&"','"&StartTime&"','"&StopTime&"','"&RunTime&"');"
Set conn=Createobject("ADODB.Connection")
conn.ConnectionString=sCon
conn.Cursorlocation=3
conn.open
Set oRs = CreateObject("ADODB.Recordset")
Set oCom=CreateObject("ADODB.Command")
oCom.commandType=1
Set oCom.ActiveConnection=conn
oCom.CommandText=sSql
Set oRs =oCom.execute
conn.close
Set oCom = Nothing
Set oRs = Nothing
Set conn=Nothing
End If
End Function