Search code examples
vb.netindexingoledbdbfdbase

Read from NTX files with Vb.NET


I'm trying to read from some DBF files that use NTX files for indexing within VB.NET. Currently, I'm having to read directly from the DBF files using OLEDB, which is ridiculously slow due to dbase's flat file method of data storage. So, I'm wondering if someone could tell me how to access the DBF files through their NTX index files within VB.NET.

If I need to download a third party library I'm okay with that, But I don't have money to pay for a third party library if it costs money. It would need to be free.

This is what I'm currently using to access the DBF Files.

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)

This however still reads directly from the DBF file and ignores the NTX indexing. Any help?

Note: I cannot "choose" to use SQL for this project as the DataBases are ones created and maintained by another application (One of considerable age). I need only access them for the data stored within.


Solution

  • Download Advantage .NET Data Provider

    This is the only example I could find. Since I do not have the files to test with this is only an example:

        '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