我写了一段代码,运行不了,求帮忙运行解决一下,代码如下
Dim Conn As New ADODB.ConnectionDim rs_reader As New ADODB.Recordset
Sub 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 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 <> 0 Then
MsgBox Err.Description
End If
End Sub
Private 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 Sub
Private Sub Command3_Click()
If Not IsNull(DataGrid1.Bookmark) 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 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()
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.Description
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set DataGrid1.DataSource = noting
rs_reader.Close
End Sub
--------------------编程问答-------------------- 哪里出错了? 错误信息呢? --------------------编程问答-------------------- 连接字符串出错的话,可以用odbdc控件生成一个.
补充:VB , 数据库(包含打印,安装,报表)