: ADODBRecordset
Picture: NewPdlo.pdl Events
Function : Sub X6309X94AE4 OnLButtonDown(Byval tem, Byval FlagsByval x, Byval y)
Line
44
Error
: 对象关闭时,不允许操作.
Suppress any further messages?
这是报错信息
Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objCon, objCom, objRe, strCon
Dim CT,sb,eb,zf,ID
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()
'conn= "Provider=SQLOLEDB;Data Source=DESKTOP-6E47LN8\WINCC;Initial Catalog=ceshi;User Id=chen;Password=chen;"
'
'objCon.ConnectionString = conn
'objCon.CursorLocation = 1
'objCon.Open()
If objCon.State = 1 Then
MsgBox "数据库已连接成功!", vbInformation, "提示"
Else
MsgBox "数据库连接失败,请检查网络连接和数据库设置。", vbCritical, "错误"
End If
'If objCon.State = adStateOpen Then
' Debug.Print "已经连接到数据库"
'Else
' Debug.Print "未连接到数据库"
'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
ID = HMIRuntime.Tags("cs_ID").Read
sq1 = "Insert Into beng_2 (ID,Time,[StartB%],[EndB%],FlowZ) Values ('"& ID &"','" & CT & "','" & sb & "','" & eb & "','" & zf & "')"
'[Time],[StartB%],[EndB%],[FlowZ]
objCom.ActiveConnection = objCon
objCom.CommandType = 1
objCom.CommandText = sq1
Set objRe = objCom.Execute
If Not (objRe Is Nothing) Then
objRe.Close
Set objRe = Nothing
End If
If Not (objCom Is Nothing) Then
Set objCom = Nothing
End If
If Not (objCon Is Nothing) Then
objCon.Close
Set objCon = Nothing
End If
'objRe.Close
'objCon.Close
'Set objRe = Nothing
'Set objCom = Nothing
'Set objCon = Nothing
End Sub
这是代码 |