Solved

How to read a DBF file using VS C#

Posted on 2014-12-19
3
312 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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now