Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:16:32+00:00 2026-05-14T23:16:32+00:00

I have a several DBF files generated by a third party that I need

  • 0

I have a several DBF files generated by a third party that I need to be able to query. I am having trouble because all of the column types have been defined as characters, but the data within some of these fields actually contain binary data. If I try to read these fields using an OleDbDataReader as anything other than a string or character array, I get an InvalidCastException thrown, but I need to be able to read them as a binary value or at least cast/convert them after they are read. The columns that actually DO contain text are being returned as expected.

For example, the very first column is defined as a character field with a length of 2 bytes, but the field contains a 16-bit integer.

I have written the following test code to read the first column and convert it to the appropriate data type, but the value is not coming out right.

The first row of the database has a value of 17365 (0x43D5) in the first column. Running the following code, what I end up getting is 17215 (0x433F). I’m pretty sure it has to do with using the ASCII encoding to get the bytes from the string returned by the data reader, but I’m not sure of another way to get the value into the format that I need, other that to write my own DBF reader and bypass ADO.NET altogether which I don’t want to do unless I absolutely have to. Any help would be greatly appreciated.

        byte[] c0;
        int i0; 

        string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ASTM;Extended Properties=dBASE III;User ID=Admin;Password=;";

        using (OleDbConnection c = new OleDbConnection(con))
        {
            c.Open();
            OleDbCommand cmd = c.CreateCommand();
            cmd.CommandText = "SELECT * FROM astm2007";
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                c0 = Encoding.ASCII.GetBytes(dr.GetValue(0).ToString());

                i0 = BitConverter.ToInt16(c0, 0);
            }
            dr.Dispose();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:16:32+00:00Added an answer on May 14, 2026 at 11:16 pm

    I am pretty sure that you are correct about the ASCII character conversions. I looked a bit for the supported scalar functions for the Jet engine but was not able to find them … or rather I found scalar functions listed but no syntax. The CONVERT function is probably what you want. Something like:

    SELECT CONVERT(twobytefield, SQL_BINARY) from astm2007
    

    Then you could call dr.GetBytes() to read the raw data. However, I was not able to construct a statement using that function that the Jet engine liked.

    If you are not able to get the conversion working, another possibility is to use the Advantage .NET Data Provider. Or the OLE DB provider (but the .NET data provider might be a better fit since you are using C#). That provider reads DBF files and supports the CONVERT scalar function. It has a free local engine.

    Since you mention you are going to try it and since I tested it to make sure I wasn’t lying, here is the code snippet I used:

    AdsConnection conn = new AdsConnection( 
       @"data source=c:\path;chartype=ansi;ServerType=local;TableType=cdx;" );
    conn.Open();
    AdsCommand cmd = conn.CreateCommand();
    cmd.CommandText = "select cast(somefield as sql_binary) from sometable";
    cmd.CommandType = CommandType.Text;
    AdsExtendedReader rdr = cmd.ExecuteExtendedReader();
    rdr.Read();
    byte[] c0 = rdr.GetBytes( 0 );
    int i0 = BitConverter.ToInt16( c0, 0 );
    Console.WriteLine( "val = {0}", i0 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
We have several jobs that run concurrently that have to use the same config
I have several old 3.5in floppy disks that I would like to backup. My
I have several applications that are part of a suite of tools that various
I have several log files of events (one event per line). The logs can
I have several ASP:TextBox controls on a form (about 20). When the form loads,
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
We have several wizard style form applications on our website where we capture information
I have several user controls, let's say A , B , C and D

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.