Solved

How to read a DBF file using VS C#

Posted on 2014-12-19
3
340 Views
Last Modified: 2014-12-24
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;
       }
0
Comment
Question by:rwheeler23
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40509223
Hi rwheeler23;

Have you given any thought of using the application configuration file to store your connection strings in. If you use the application config file you can give each connection string a name and be able to retrieve it from the file by that name. Have a look at this web post for info.

Connection Strings and Configuration Files
0
 

Author Comment

by:rwheeler23
ID: 40510161
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
0
 

Author Closing Comment

by:rwheeler23
ID: 40517023
I do not understand these files. However I was able to find an export tool and that is all I need for now.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question