这里有个问题想请教一下,就是在用VB写的程序用ADO访问不到数据库的,是怎么回事。
运行时出面以下的情况:
1、Data error event hit err:[ADODC]:没有指定记录源。[ADO]:没有为命令对象设置命令。
2、Data error event hit err:[Microsoft][ODBC驱动程序管理器]未发现数据源名称并且未指定默认驱动程序。
最后出面:实时错误'-2147467259(800040050) 对象‘REFRESH’的方法‘IAdodc‘失败。
我的链接语句是:
Private Sub Form_Load()
Me.datPrimaryRS.ConnectionString = " PROVEIDER=Microsoft.Jet.OLEDB.8.51;DataSOURCE= " & App.Path & "\database\信息科97.mdb; "
Me.datPrimaryRS.RecordSource = "select 类别,品牌,型号,机身序列号,购入时间,配置信息,使用部门,使用人,使用情况,注销原因 from 信息表 Order by 购入时间"
Me.datPrimaryRS.Refresh
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 Frame2_DragDrop(Source As Control, X As Single, Y As Single)
End Sub