ADO和机器的配置无关
给你一个简单的ADO连接类,看看

- Private pConnection As New ADODB.Connection
- Private pRecordset As New ADODB.Recordset
- Private pFileName As String
- Private Sub OpenConnection()
- With pConnection
- If .State = adStateOpen Then .Close
- .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pFileName & ";Persist Security Info=False"
- .Open
- End With
- End Sub
- Public Function OpenRecordset(ByVal strSql As String) As ADODB.Recordset
- Dim myRecordset As New ADODB.Recordset
- With myRecordset
- .CursorLocation = adUseClient
- .CursorType = adOpenDynamic
- .Open strSql, pConnection, , , adCmdText
- End With
- Set pRecordset = myRecordset
- Set OpenRecordset = pRecordset
- End Function
- Public Function RunTrans(ByVal tranSql As String)
- pConnection.BeginTrans
- pConnection.Execute tranSql
- pConnection.CommitTrans
- End Function
- Public Sub Move(ByVal NumRecords As ADO_LONGPTR, Optional ByVal Start)
- If IsMissing(Start) Then
- pRecordset.Move NumRecords
- Else
- pRecordset.Move NumRecords, Start
- End If
- End Sub
- Public Sub MoveFirst()
- pRecordset.MoveFirst
- End Sub
- Public Sub MoveLast()
- pRecordset.MoveLast
- End Sub
- Public Sub MoveNext()
- pRecordset.MoveNext
- End Sub
- Public Sub MovePrevious()
- pRecordset.MovePrevious
- End Sub
- Public Property Let FileName(ByVal str As String)
- Dim fso As New FileSystemObject
- str = UCase(str)
- If fso.FileExists(str) Then
- If str <> pFileName Then
- pFileName = str
- OpenConnection
- End If
- Else
- MsgBox "文件不存在!"
- End If
- End Property
- Public Property Get Item(Index As Integer)
- Item = pRecordset.Fields(Index).Value
- End Property
- Public Property Get Count()
- Count = pRecordset.RecordCount
- End Property
- Public Property Get EOF()
- EOF = pRecordset.EOF
- End Property
- Public Property Get BOF()
- BOF = pRecordset.BOF
- End Property
- Private Sub Class_Terminate()
- On Error Resume Next
- pRecordset.Close
- Set pRecordset = Nothing
- pConnection.Close
- Set pConnection = Nothing
- End Sub
|