Avatar of rwheeler23
rwheeler23
Flag for United States of America asked on

How to read a DBF file using VS C#

I have this code that establishes a connection to a series of dbf files. My question now is how to point it to any one particular file, open that file and proceed to read the records? My ultimate goal here is to parse each record and then via a SQL connection transfer the data from dbase to SQL.

       private OdbcConnection GetDBFConnection()
       {
           /* Create reader and open file containing connection string */
           TextReader tr = new StreamReader(@"DBF.INI");

           /* Read line containing the connection string */
           DBFConnectionString = tr.ReadLine();

           /* Close the stream */
           tr.Close();

           try
           {
               DBFDataConnection = new System.Data.Odbc.OdbcConnection(DBFConnectionString);
               DBFDataConnection.Open();
           }
           catch (Exception ex)
           {
               string eMsg = "Error-Opening SQL connection: " + ex.Message;
               if (StackTraceWanted) eMsg += "\n" + ex.StackTrace;
               MessageBox.Show(eMsg);
           }

           return DBFDataConnection;
       }
C#

Avatar of undefined
Last Comment
rwheeler23

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rwheeler23

ASKER
I found a Dbase reader that can read these types of dbf file. I can use their export tool to dump out to csv or Excel. I do not understand why my connect string did not allow this. These are the file types this program can read.

•dBASE PLUS
•Personal dBASE
•dB2K
•Visual dBASE 7.5
rwheeler23

ASKER
I do not understand these files. However I was able to find an export tool and that is all I need for now.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes