VB与access数据库连接出问题,请各位帮忙看看怎么回事。
我用向导生成的一个管理系统,把其中系统自动生成的连接字符串和命令文本删了,改成运行程序时自动加载Private Sub Form_Load()里的内容,但一编译就报错:“过程声明与同名事件或过程的描述不匹配”。请问各位这是怎么回事?代码如下:
Private Sub Command1_Click()
Dim str As String
If Combo1.Text = "" Or Text1.Text = "" Then
MsgBox "请输入查询条件和内容!"
Exit Sub
End If
str = Combo1.Text & "like" & "'" & Text1.Text & "'"
datPrimaryRS.Recordset.Fields str
If datPrimaryRS.Recordset.AbsolutePosition < adPosBOF Then
MsgBox "没有相关的记录!"
datPrimaryRS.Recordset.MoveFirst
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
End Sub
Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
'错误处理程序代码置于此处
'想要忽略错误,注释掉下一行
'想要捕获它们,在此添加代码以处理它们
MsgBox "Data error event hit err:" & Description
End Sub
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'为这个 recordset 显示当前记录位置
datPrimaryRS.Caption = "Record: " & CStr(datPrimaryRS.Recordset.AbsolutePosition)
End Sub
Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'验证代码置于此处
'下列动作发生时该事件被调用
Dim bCancel As Boolean
Select Case adReason
Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select
If bCancel Then adStatus = adStatusCancel
End Sub
Private Sub cmdAdd_Click()
On Error GoTo AddErr
datPrimaryRS.Recordset.AddNew
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
With datPrimaryRS.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
Exit Sub
DeleteErr:
MsgBox Err.Description
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.datPrimaryRS.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.8.51;DataSource=" & App.Path & "\database\助学贷款管理系统.mdb;"
Me.datPrimaryRS.RecordSource = "Select ID,姓名,性别,学号,身份证号,专业,住址,邮编,合同号,毕业,第一次划款,第一次划款时间,第二次划款,第二次划款时间,第三次划款,第三次划款时间,第四次划款,第四次划款时间 from 学生信息表 Order by ID"
Me.datPrimaryRS.Refresh
End Sub