使用 Vb.NET 从 NTX 文件中读取

Read from NTX files with Vb.NET

我正在尝试读取一些使用 NTX 文件在 VB.NET 中进行索引的 DBF 文件。目前,我不得不使用 OLEDB 直接从 DBF 文件中读取,由于 dbase 的平面文件数据存储方法,这速度慢得离谱。所以,我想知道是否有人可以告诉我如何通过 VB.NET.

中的 NTX 索引文件访问 DBF 文件

如果我需要下载第三方库我可以接受,但是如果第三方库要花钱我没钱买。它需要是免费的。

这是我目前用来访问 DBF 文件的文件。

Private Shared ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Settings.DataPath & ";Extended Properties=dBase IV"
Public Shared dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM `PAGES.NTX` WHERE `PAGE_NUM` BETWEEN 241 AND 270", dBaseConnection)
Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)

然而,这仍然直接从 DBF 文件读取并忽略 NTX 索引。有帮助吗?

注意:我不能"choose"为这个项目使用SQL,因为数据库是由另一个应用程序(一个相当大的年龄)创建和维护的。我只需要访问它们以获取其中存储的数据。

下载Advantage .NET Data Provider

这是我能找到的唯一示例。由于我没有要测试的文件,这只是一个例子:

    'Set the TypeTable to NTX
    Dim conn As New AdsConnection("data source=c:\data;" + "ServerType=remote|local; TableType=NTX")
    Dim cmd As AdsCommand
    Dim reader As AdsDataReader
    Dim iField As Integer

    Try

        ' make the connection to the server
        conn.Open()

        ' create a command object
        cmd = conn.CreateCommand()

        ' specify a simple SELECT statement
        cmd.CommandText = "select * from departments"

        ' execute the statement and create a reader
        reader = cmd.ExecuteReader()

        ' dump the results of the query to the console
        While reader.Read()
            For iField = 0 To reader.FieldCount - 1
                Console.Write(reader.GetValue(iField) + " ")
            Next
            Console.WriteLine()
        End While

        conn.Close()
    Catch e As AdsException
        ' print the exception message
        Console.WriteLine(e.Message)
    End Try