Home > Software engineering >  I wrote a piece of code, can't run, please help to solve the operation, the code is as follows
I wrote a piece of code, can't run, please help to solve the operation, the code is as follows

Time:11-02

Dim Conn As New ADODB. Connection
Dim rs_reader As New ADODB. You

Sub Data ()
On Error GoTo Err
Dbpath=App. Path & amp; "\ book MDB
"The ConnectionString="provider=Microsoft. Jet. The oledb. 4.0. Data source="& amp; Dbpath
Conn. Open the ConnectionString
Err:
If Err. Number Then
MsgBox "database error
"End
End the If

End Sub

Private Sub Command1_Click ()
Dim answer As String
On Error GoTo cmdmodify
Cmddel. Enabled=False
Cmdmodify. Enabled=False
Cmdupdate. Enabled=True
Cmdcancel. Enabled=True
DataGrid1. AllowUpdate=True
Cmdmodify:
If Err. Number & lt;> 0 Then
MsgBox Err. The Description
End the If
End Sub

Private Sub Command2_Click ()
Dim answer As String
On Error GoTo delerror
Answer=MsgBox (" sure you want to delete?" VbYesNo, "")
If answer=vbYes Then
DataGrid1. AllowDelete=True
Rs_reader. Delete
Rs_reader. Update
DataGrid1. Refresh
MsgBox "deleted successfully!" , vbOKOnly + vbExclamation
DataGrid1. AllowDelete=False
The Else
The Exit Sub
End the If
Delerror:
If Err. Number & lt;> 0 Then
MsgBox Err. The Description
End the If
End Sub

Private Sub Command3_Click ()
If Not IsNull (DataGrid1. A Bookmark) Then
Rs_reader. Update
End the If
Cmddel. Enabled=True
Cmdmodify. Enabled=True
Cmdupdate. Enabled=False
Cmdcancel. Enabled=False
DataGrid1. AllowUpdate=False
MsgBox "success!" , vbOKOnly + vbExclamation, ""
End Sub

Private Sub Command4_Click ()
Rs_reader. CancelUpdate
DataGrid1. Refresh
DataGrid1. AllowAddNew=False
DataGrid1. AllowUpdate=False
Cmdmodify. Enabled=True
Cmdcancel. Enabled=False
Cmdupdata. Enabled=False
End Sub

Private Sub Form_Load ()
The Call Data
Dim As SQL String
On Error GoTo loaderror
Aql="select * from books category"
Rs_reader. CursorLocation=adUseClient
Rs_reader. The Open SQL, Conn, adOpenKeyset, adLockPessimistic
Cmdupdate. Enable=False
DataGrid1. AllowAddNew=False
DataGrid1. AllowDelete=False
DataGrid1. AllowUpdate=False
If userpow="guest" Then
Frame2. Enabled=False
End the If
The Set DataGrid1. The DataSource=rs_reader
The Exit Sub
Loaderror:
MsgBox Err. The Description

End Sub

Private Sub Form_Unload (Cancel As Integer)
The Set DataGrid1. The DataSource=noting
Rs_reader. Close
End Sub

CodePudding user response:

Something wrong? The error message?

CodePudding user response:

Connection string are wrong, you can use odbdc generates a control.
  • Related