我正在使用 WINCC 在 SQL Server 中保存数据,但我无法插入当前数据和时间 帮我解决这个问题
Sub OnClick(ByVal Item)
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=winnrc;UID=;PWD=;"
lngValue = HMIRuntime.Tags("JOB_ID").Read(1)
strSQL = "INSERT INTO NEWDATA (JOB_ID,SHIFT,QTY,WEIGHT,DECREASING_ST,DECREASING_TEMP_PV,DECREASING_LEVEL,CASCADE_RINSE_T4_ST,CASCADE_RINSE_T4_TEMP_PV,CASCADE_RINSE_T4_LEVEL,CASCADE_RINSE_T3_ST,CASCADE_RINSE_T3_TEMP_PV,CASCADE_RINSE_T3_LEVEL,PHOSPHATE_ST,PHOSPHATE_TEMP_PV,PHOSPHATE_LEVEL,trigger_0) VALUES (" & HMIRuntime.Tags("REPORT_BLOCK_JOB_ID").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_SHIFT").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_QUANTITY").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_WEIGHT").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_DECREASING_ST").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_DECREASING_TEMP_PV").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_DECREASING_LEVEL").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T4_ST").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T4_TEMP_PV").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T4_LEVEL").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T3_ST").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T3_TEMP_PV").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_CASCADE_RINSE_T3_LEVEL").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_PHOSPHATE_ST").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_PHOSPHATE_TEMP_PV").Read(1) & "," & HMIRuntime.Tags("REPORT_BLOCK_PHOSPHATE_LEVEL").Read(1) & "," & HMIRuntime.Tags("trigger_0").Read(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
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub