想要把wincc内部数据导入Access中,按照《深入浅出》编了一段VBS的程序,但是没有运行。我在D盘建立了一个名叫dbsample的Access文件,命名了一个data的数据表里建立tagvalue的列。还有Access文件建立在哪里都可以么?我没有接触过数据库,对于书上说得创建ODBC数据源不是很理解,请高手们指教!!!!
Sub OnRButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=dbsample;UID=;PWD=;"
lngValue = HMIRuntime.Tags("Tag1").Read
strSQL = "INSERT INTO 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
End Sub