在博途V15 wincc画面中设置了一个按钮空间,插入vbscript函数,点击后,给创建好的Access2016数据库中写数据。
Dim strConnectionString,objconnection,strsql,objcommand
'strConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source="&"C:\Plc_Data\WiccData_Test_1.accdb"&";"
strConnectionString="Provider=MSDASQL;DSN=SampleDSN;"
Set objconnection=CreateObject("ADODB.Connection")
objconnection.ConnectionString=strConnectionString
objconnection.Open
'msgbox(OK)
strsql="Insert into Qd_table1 (Qd_Count) values (1);"
Set objcommand=CreateObject("ADODB.Command")
With objcommand
.ActiveConnection=objConnection
.CommandText=strSQL
End With
objcommand.Execute
Set objcommand=Nothing
objconnection.Close
Set objconnection=Nothing
这个代码单独.vbs执行,可以写入数据,但是放在wincc的函数中,用msgbox查了一下过程,原因是在wincc函数执行过程中打不开数据库(objconnection.open不执行),郁闷一天了,求大神解答!
ODBC都是设置好的,因为单独.vbs可以执行。

