Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C#

Paradox database native .NET reader

Rate me:
Please Sign up or sign in to vote.
4.87/5 (30 votes)
17 Mar 2011CPOL4 min read 193.6K   5.3K   54  
Read contents of a Paradox database in pure .NET code without using BDE or other libraries; index support included.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using ParadoxReader;

namespace ParadoxTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "data");

            Console.WriteLine("Test 1: sequential read first 10 records from start");
            Console.WriteLine("==========================================================");
            var table = new ParadoxTable(dbPath, "zakazky");
            var recIndex = 1;
            foreach (var rec in table.Enumerate())
            {
                Console.WriteLine("Record #{0}", recIndex++);
                for (int i=0; i<table.FieldCount; i++)
                {
                    Console.WriteLine("    {0} = {1}", table.FieldNames[i], rec.DataValues[i]);
                }
                if (recIndex > 10) break;
            }
            Console.WriteLine("-- press [enter] to continue --");
            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("Test 2: read 10 records by index (key range: 1750 -> 1760)");
            Console.WriteLine("==========================================================");

            var index = new ParadoxPrimaryKey(table, Path.Combine(dbPath, "zakazky.PX"));
            var condition =
                new ParadoxCondition.LogicalAnd(
                    new ParadoxCondition.Compare(ParadoxCompareOperator.GreaterOrEqual, 1750, 0, 0),
                    new ParadoxCondition.Compare(ParadoxCompareOperator.LessOrEqual, 1760, 0, 0));
            var qry = index.Enumerate(condition);
            var rdr = new ParadoxDataReader(table, qry);
            recIndex = 1;
            while (rdr.Read())
            {
                Console.WriteLine("Record #{0}", recIndex++);
                for (int i = 0; i < rdr.FieldCount; i++)
                {
                    Console.WriteLine("    {0} = {1}", rdr.GetName(i), rdr[i]);
                }
            }
            Console.WriteLine("-- press [enter] to continue --");
            Console.ReadKey();

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Petr Bříza
Czech Republic Czech Republic


Freelance .NET developer from Prague, Czech republic. You have a problem - I am the solution.

Visit me at http://petr.briza.net.


Comments and Discussions