|
下面是连接的一例子:
F:\cutplan\cad_dbf\data\dby_csr.dbf,必须是存在的!
Sub checkBDF()
Dim Cn As New ADODB.Connection
Dim nRs As New ADODB.Recordset
Dim ProSQL$, SQL$, i%
NewPath = "F:\cutplan\cad_dbf\data"
ProSQL = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=" & NewPath & ";"
On Error GoTo 9
Cn.Open ProSQL
SQL = "select * from [dby_csr.dbf] "
Set nRs = Nothing
nRs.Open SQL, Cn, 1, 1, 1
If Not nRs.EOF Then
With ActiveSheet
For i = 1 To nRs.Fields.Count: .Cells(1, 10 + i) = nRs.Fields(i - 1).Name: Next
.Cells(2, 11).CopyFromRecordset nRs
End With
End If
A = A
Set rs = Nothing
Set Cn = Nothing
Exit Sub
9:
MsgBox Err.Description
set cn=nothing
End Sub |
|