Office中国论坛/Access中国论坛

标题: 请问如何用代码打开dbf数据库? [打印本页]

作者: sino77    时间: 2003-6-6 00:00
标题: 请问如何用代码打开dbf数据库?
各位大虾好。我用access的导入外部数据库功能(选择dbase 5格式)可以导入dbf数据库,但我不知道用代码该如何实现。我打开dbf数据库的目的是要对其进行查询,然后将其查询结果报存在access数据库的表中。但我不想直接把dbf数据库导入access中。请问各位大虾有什么比较简洁的办法吗?谢谢。
作者: susanyjj    时间: 2003-7-12 19:15
我也很想知道.....
谢谢......
作者: hamletl    时间: 2003-7-17 20:11
''' 假如我们有一个CUSTOMER.dbf 在C:\ 后
''' NOTE: This subroutine requires that you reference the
'''       latest version of the following library:
'''
'''         Microsoft ActiveX Data Objects Library

    Dim conn As ADODB.Connection
    Dim rst As ADODB.Recordset
    '
    Dim i As Integer

    ' Create the Connection object.
    Set conn = New ADODB.Connection

    PathToDatabase = "c:\"
    With conn
        'Assign the connection string to the connection object.
        .ConnectionString = "DRIVER={Microsoft dBase Driver (*.dbf)};" & _
            "DBQ=" & PathToDatabase & ";" & _
            "DefaultDir=" & PathToDatabase & "\"
        ' Open the connection.
        .Open strConn
    End With

    ' Create a new Recordset Object.
    Set rst = New ADODB.Recordset
   
    With rst
        ' Connect this recordset to the previously opened connection.
        .ActiveConnection = conn
        ' Retrieve all records from the Customer table.
        .Open "SELECT * FROM Customer"
        
    End With

    ' 由此得出DBF 数据集。
    Set rst = Nothing
    ' Close the Connection.
    conn.Close

改自微软实例 HAMLETL

[此贴子已经被作者于2003-7-17 12:12:02编辑过]


作者: liujiangyuan.nm    时间: 2009-6-22 16:05
看不懂




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3