Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objCon, objCom, objRe, strCon
Dim CT,sb,eb,zf
Dim sq1
Set objCon = CreateObject("ADODB.Connection")
Set objCom = CreateObject("ADODB.Command")
Set objRe = CreateObject("ADODB.Recordset")
strCon = "Provider=SQLOLEDB;Data Source=DESKTOP-6E47LN8\WINCC;Initial Catalog=ceshi;User Id=chen;Password=chen;"'Integrated Security=SSPI;Persist Info=False;
objCon.ConnectionString = strCon
objCon.CursorLocation = 1
objCon.Open()
If objCon.State = 1 Then
MsgBox "数据库已连接成功!", vbInformation, "提示"
Else
MsgBox "数据库连接失败,请检查网络连接和数据库设置。", vbCritical, "错误"
End If
CT = HMIRuntime.Tags("cs_time").Read
sb = HMIRuntime.Tags("cs_start_B").Read
eb = HMIRuntime.Tags("cs_end_B").Read
zf = HMIRuntime.Tags("cs_flow_Z").Read
sq1 = "Insert Into beng_2 (ID,Time,[StartB%],[EndB%],FlowZ) Values ('1','" & CT & "','" & sb & "','" & eb & "','" & zf & "')"
'[Time],[StartB%],[EndB%],[FlowZ]
objCom.ActiveConnection = objCon
objCom.CommandType = 1
objCom.CommandText = sq1
Set objRe = objCom.Execute
objRe.Close
objCon.Close
Set objRe = Nothing
Set objCom = Nothing
Set objCon = Nothing
End Sub
检查错误 |