发表于:2008-03-02 23:43:00
4楼
Introduction
In this example, a tag value is written from WinCC to an Access database via an ODBC driver. The example does not contain error handling.
Procedure
1. Create the Access database with the WINCC_DATA table and (ID, TagValue) columns with the ID as the Auto Value.
2. Set up the ODBC data source with the name "SampleDSN" reference to the above Access database.
3. Programming.
Example
'VBS108
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"
lngValue = HMIRuntime.Tags("Tag1").Read
strSQL = "INSERT INTO WINCC_DATA (TagValue) VALUES (" & lngValue & ");"
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
wincc6.0手册里的例子,我试过好使。