vb 中连接无法用于执行此操作,在此上下文中它可能已被关闭或无效! 求教怎么解决?
PrivateSubCommand3_Click()DimKAsIntegerDimrsAsADODB.RecordsetDimconnAsADODB.Connectio...
Private Sub Command3_Click()
Dim K As Integer
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Dim sqlStr As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\mary\Desktop\机柜表\机柜表\机柜表.mdb;Persist Security Info=False"
sqlStr = "select * from JGB"
rs.Open sqlStr, conn, adOpenKeyset, adLockOptimistic '这句话报错,下面的都运行不到
If Not rs.EOF Then
rs.MoveFirst
End If
For K = 1 To rs.RecordCount
If rs("ID") = Trim(Text1.Text) Then
rs("MONEY") = Val(Text3.Text)
rs.Update
MsgBox "修改成功!", vbOKOnly
GoTo 100
End If
rs.MoveNext
Next K
MsgBox "修改失败!", vbOKOnly
100
rs.Close
Set conn = Nothing
End Sub
用的下面两个部件
Microsoft ADO Data Control 6.0
Microsoft Hierarchical Flexgrid Control 6.0 展开
Dim K As Integer
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Dim sqlStr As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\mary\Desktop\机柜表\机柜表\机柜表.mdb;Persist Security Info=False"
sqlStr = "select * from JGB"
rs.Open sqlStr, conn, adOpenKeyset, adLockOptimistic '这句话报错,下面的都运行不到
If Not rs.EOF Then
rs.MoveFirst
End If
For K = 1 To rs.RecordCount
If rs("ID") = Trim(Text1.Text) Then
rs("MONEY") = Val(Text3.Text)
rs.Update
MsgBox "修改成功!", vbOKOnly
GoTo 100
End If
rs.MoveNext
Next K
MsgBox "修改失败!", vbOKOnly
100
rs.Close
Set conn = Nothing
End Sub
用的下面两个部件
Microsoft ADO Data Control 6.0
Microsoft Hierarchical Flexgrid Control 6.0 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询