Click here to Skip to main content
12,821,284 members (40,933 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 24 Aug 2007


, 24 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An article for converting DBF files to dataset XML files


Hello, there. This is my first contribution to The Code Project; I hope you enjoy it. This is a simple project for converting and merging DBF FoxPro files to an XML file, so you can then load it via Dataset.ReadXml(). I did it because I had a lot of DBF files that I wanted to merge and read in an easier way than with VFP.


In this project, I used the concepts below:

  • DbProviderFactory
  • BackgroundWorker

Using the Code

The project consists of a single form with a local DataSet at the form's level. the form reads a default directory in the config file and then loads the DBF files in that directory in a ListBox. This is the code for filling the ListBox with the DBF files:

private void RefrescarDirectorio(string directorio) 
    DirectoryInfo d = new DirectoryInfo(directorio);
    FileInfo[] tablas = d.GetFiles("*.dbf");
    // Cargar dbf's de la ruta

    lstTablas.DataSource = tablas;
    lstTablas.DisplayMember = "Name";

Then the users can select the DBF files that they want exported, provide a name for the data table and then click Export. This process can be repeated for any DBF files.

Note that if there exists a data table in the DataSet, the program will try to load the data table with the data in the DBF through Datatable.Load(DataReader). No Exception is thrown if the structure of the data table is different from that of the DBFs to merge; that behavior will not be controlled.

This is the code for filling the dataset with the DBFs selected. It is called from within BackgroundWorker.

DbProviderFactory f = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection cn = f.CreateConnection();
cn.ConnectionString = 
    "Provider=vfpoledb.1;Data Source=" + txtRutaDbf.Text + 
    ";Collating Sequence=general;";
foreach (FileInfo fInfo in lstTablas.SelectedItems) 
    string archivo = fInfo.Name;
    string comando = "SELECT * FROM " + archivo;
    DbCommand cm = cn.CreateCommand();
    cm.CommandText = comando;
    catch (Exception) 

Points of Interest

It's curious to see how the Load and Merge methods of the DataTable object don't take into account the structure of the current table.


  • 2007-08-23 First release


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


About the Author

Web Developer
Colombia Colombia
I am Jhonny D Cano. I'm from Colombia, i'm professional in systems engineering. I worked since 1998 in Visual Basic and C++, then in 2.003 I jumped out to .Net development platform (VB.Net) and then i started with C#. I have a solid background in Windows Forms and in my current job I am working with ASP.Net and Web Services over Oracle and SQL Server. Alternatively I got the SUN Certification "Java Certified Programmer" and currently i'm in the process of 70-356's certification .

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
dexterama8-Apr-13 7:53
memberdexterama8-Apr-13 7:53 
GeneralPlease Help Me , I very need it !!!! [modified] Pin
hoavan_le5-Nov-07 17:08
memberhoavan_le5-Nov-07 17:08 
GeneralRe: Please Help Me , I very need it !!!! Pin
canozurdo15-Nov-07 3:49
membercanozurdo15-Nov-07 3:49 
GeneralJust what I needed Pin
marknm18-Oct-07 5:34
membermarknm18-Oct-07 5:34 
Generalcan't use this Pin
Jannigje at CC10-Oct-07 5:31
memberJannigje at CC10-Oct-07 5:31 
GeneralRe: can't use this Pin
canozurdo10-Oct-07 8:11
membercanozurdo10-Oct-07 8:11 
GeneralI can't run it Pin
hoavan_le5-Nov-07 4:11
memberhoavan_le5-Nov-07 4:11 
QuestionHow do you save it back as DBF file after the merge? Pin
danielc1268-Sep-07 16:45
memberdanielc1268-Sep-07 16:45 
AnswerRe: How do you save it back as DBF Pin
canozurdo13-Sep-07 3:46
membercanozurdo13-Sep-07 3:46 
GeneralRe: How do you save it back as DBF Pin
jcraigue1-Jul-11 12:32
memberjcraigue1-Jul-11 12:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 24 Aug 2007
Article Copyright 2007 by canozurdo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid