我可以和你分享一些代碼,我使用WinCC flexible 2008用於插入到數據庫中的簡單記錄afeter由工廠完成任何配方。
'------------------------------------------------------------
Dim sServer,sDataBaseName ,sConn,oConn,oRS, FetchData
Dim sUserName,sPassWord
Dim adOpenKeyset, adLockOptimistic, adCmdTable
Dim mRecordstr, tableName
Dim field
Dim loc_PRESSURE
Dim loc_ENDDATETIME
Dim loc_RECEIPE
Dim loc_BEGINDATETIME
Dim loc_USER
Dim loc_TEMPERATURE
loc_USER = SmartTags("DatabaseSQL\var_USER")
loc_BEGINDATETIME = CDate(SmartTags("DatabaseSQL\var_BEGINDATETIME"))
loc_ENDDATETIME = CDate(SmartTags("DatabaseSQL\var_ENDDATETIME"))
loc_RECEIPE = SmartTags("DatabaseSQL\var_RECEIPE")
loc_PRESSURE = SmartTags("DatabaseSQL\var_PRESSURE")
loc_TEMPERATURE = SmartTags("DatabaseSQL\var_TEMPERATURE")
sServer = "192.168.40.3" 'e.g
sDataBaseName = "DBPLC"
sUserName = "USER"'INSERT USER NAME ENABLED IN DATABASE
sPassWord = "SECRETPASSWORD" '
tableName = "TABLE_PLC"
adOpenKeyset = 1
adLockOptimistic = 3
adCmdTable = 2
sConn="DRIVER={SQL Server};SERVER=" & sServer & ";DATABASE=" & sDataBaseName & ";Encrypt=NO;"
Set oConn = CreateObject("ADODB.Connection")
oConn.CommandTimeout = 36000
oConn.Open sConn, sUserName, sPassWord
Set FetchData = CreateObject("ADODB.Recordset")
'FetchData.open "SELECT * FROM TABLE_PLC", oConn, 3
FetchData.Open tableName, oConn, adOpenKeyset, adLockOptimistic, adCmdTable
FetchData.AddNew
FetchData.Fields("USER").Value = loc_USER
FetchData.Fields("BEGINDATETIME").Value = loc_BEGINDATETIME
FetchData.Fields("ENDDATETIME").Value = loc_ENDDATETIME
FetchData.Fields("RECEIPE").Value = loc_RECEIPE
FetchData.Fields("PRESSURE").Value = loc_PRESSURE
FetchData.Fields("TEMPERATURE").Value = loc_TEMPERATURE
FetchData.Update
FetchData.Close
oConn.Close
本例中的WinCC變量保存在名爲「DatabaseSQL」的文件夾下。 – RammRras