Dim Conn As New ADODB.Connection
Dim rs_reader As New ADODB.RecordsetSub Data()
On Error GoTo Err
Dbpath = App.Path & "\book.mdb"
ConnectionString = "provider=Microsoft.Jet.oledb.4.0;data source=" & Dbpath
Conn.Open ConnectionString
Err:
If Err.Number Then
MsgBox "数据库出错"
End
End IfEnd SubPrivate 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 <> 0 Then
MsgBox Err.Description
End If
End SubPrivate Sub Command2_Click()
Dim answer As String
On Error GoTo delerror
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
    DataGrid1.AllowDelete = True
    rs_reader.Delete
    rs_reader.Update
    DataGrid1.Refresh
    MsgBox "成功删除!", vbOKOnly + vbExclamation
    DataGrid1.AllowDelete = False
    Else
    Exit Sub
    End If
delerror:
    If Err.Number <> 0 Then
    MsgBox Err.Description
    End If
End SubPrivate Sub Command3_Click()
If Not IsNull(DataGrid1.Book) Then
    rs_reader.Update
    End If
    cmddel.Enabled = True
    cmdmodify.Enabled = True
    cmdupdate.Enabled = False
    cmdcancel.Enabled = False
    DataGrid1.AllowUpdate = False
    MsgBox "修改成功!", vbOKOnly + vbExclamation, ""
End SubPrivate Sub Command4_Click()
rs_reader.CancelUpdate
DataGrid1.Refresh
DataGrid1.AllowAddNew = False
DataGrid1.AllowUpdate = False
cmdmodify.Enabled = True
cmdcancel.Enabled = False
cmdupdata.Enabled = False
End SubPrivate Sub Form_Load()
Call Data
Dim sql As String
On Error GoTo loaderror
aql = "select * from 书刊类别"
rs_reader.CursorLocation = adUseClient
rs_reader.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 If
Set DataGrid1.DataSource = rs_reader
Exit Sub
loaderror:
MsgBox Err.DescriptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)
Set DataGrid1.DataSource = noting
rs_reader.Close
End Sub