求教Wincc导出数据问题
按钮动作调用了VBS脚本,用来往access里写入数据。之前已建立access文件以及数据表格,但是按下按钮数据并没有写入。请教下是不是程序哪里出了问题?再请教下strConnectionString="Provider=MSDASQL;DSN=GSProcessValueData;UID=;PID=;" 里面的MSDASQL DSN UID PID 都是什么意思啊?谢谢啦
程序如下:
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)
Dim objConnection 'define connection
Dim strConnectionString 'define connection string
' define process tag for SQL
Dim Q1,Q2,Q4,Frequency,Power,SMassQ,SVolQ,P1,P2,P3,P4,P5,P6,T1,T2,Valve1,FrequencySet,Valve3,Valve4
Dim WeightValue,WeightRate,RecordTime,WeightChange,ChangeRate,SolidDensity,SInGRate
Dim strSQL
Dim objCommand
strConnectionString="Provider=MSDASQL;DSN=GSProcessValueData;UID=;PID=;"
Q1=HMIRuntime.Tags("Quanlity1").Read
Q2=HMIRuntime.Tags("Quanlity2").Read
Q4=HMIRuntime.Tags("Quanlity4").Read
Frequency=HMIRuntime.Tags("FrequencyOutput").Read
Power=HMIRuntime.Tags("PowerOutput").Read
SMassQ=HMIRuntime.Tags("WeightRate").Read 'it should be modified when Mass is got
SVolQ=HMIRuntime.Tags("FrequencyOutput").Read 'it should be modified when Mass is got
P1=HMIRuntime.Tags("Pressure1").Read
P2=HMIRuntime.Tags("Pressure2").Read
P3=HMIRuntime.Tags("Pressure3").Read
P4=HMIRuntime.Tags("Pressure4").Read
P5=HMIRuntime.Tags("Pressure5").Read
P6=HMIRuntime.Tags("Pressure6").Read
T1=HMIRuntime.Tags("Temp1").Read
T2=HMIRuntime.Tags("Temp2").Read
Valve1=HMIRuntime.Tags("AjustSet1").Read
FrequencySet=HMIRuntime.Tags("AjustSet2").Read
Valve3=HMIRuntime.Tags("AjustSet3").Read
Valve4=HMIRuntime.Tags("AjustSet4").Read
WeightValue=HMIRuntime.Tags("ChengZhongOutput").Read
'WeightRate=HMIRuntime.Tags("WeightRate").Read
RecordTime=HMIRuntime.Tags("RecordTime").Read
WeightChange=HMIRuntime.Tags("WeightChange").Read
ChangeRate=HMIRuntime.Tags("AverageChange").Read
SolidDensity=HMIRuntime.Tags("SolidDensity").Read
SInGRate=HMIRuntime.Tags("SInGRate").Read
strSQL="INSERT INTO ProcessValue(Q1,Q2,Q4,Frequency,Power,SMassQ,SVolQ,P1,P2,P3,P4,P5,P6," _
& "T1,T2,Valve1,FrequencySet,Valve3,Valve4,WeightValue,RecordTime,WeightChange,ChangeRate," _
& "SolidDensity,SInGRate) VALUES (" & Q1 & "," & Q2 & "," & Q4 _
& "," & Frequency & "," & Power & "," & SMassQ & "," & SVolQ & "," & P1 & "," & P2 _
& "," & P3 & "," & P4 & "," & P5 & "," & P6 & "," & T1 & "," & T2 & "," & Valve1 _
& "," & FrequencySet & "," & Valve3 & "," & Valve4 & "," & WeightValue _
& "," & RecordTime & "," & WeightChange & "," & ChangeRate & "," & SolidDensity _
& "," & SInGRate & ")"
'strSQL="insert into Table1 values(1,1)"
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
MsgBox "success"
Set objCommand=Nothing
objConnection.Close
Set objConnection=Nothing
End Sub
最佳答案
strConnectionString="Provider=MSDASQL;DSN=GSProcessValueData;UID=;PID=;" 表示通过ODBC方式连接数据库,所以你应该检查是否建立了名为GSProcessValueData的ODBC数据源,你可以通过GSC诊断窗口调试查看,如果没有连接到数据库,在该窗口中会有出错信息显示。
提问者对于答案的评价:
谢谢啦 的确是没有定义数据源
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc274236.html