脚本如下:
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim lngValuea
Dim lngValueb
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;" //SampleDSN为ODBC数据源
lngValuea = HMIRuntime.Tags("A2").Read
lngValueb = HMIRuntime.Tags("A1").Read
strSQL = "INSERT INTO wincc (lngValuea,lngValueb)values("&lngvaluea&","&lngvalueb&");"
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
ACCESS需要事先建立,并在ODBC建立源,连接指向建立的ACCESS文档。