Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 8856

C# Read and convert dbf file to xml

I want to read a simple foxpro dbf file and convert it into xml file and save it into my pc. Is it possible to read and convert simple file.DBF with out using any db connection?

Upvotes: 1

Views: 5712

Answers (2)

matrix
matrix

Reputation: 3100

Here is the code...

    private void btnBrowse_Click(object sender, EventArgs e)
    {
        try
        {
            var path = "F:\\Projects\\dbf"; // Path of the folder containing dbf file.
            var fileName = "Invoices1.dbf";
            var constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=DBASE III";
            var sql = "select * from " + fileName;
            var ds = new DataSet();

            using (var con = new OleDbConnection(constr))
            {
                con.Open();

                using (var cmd = new OleDbCommand(sql, con))
                {
                    using (var da = new OleDbDataAdapter(cmd))
                    {
                        da.Fill(ds);
                        dataGridView1.DataSource = ds.Tables.Count > 0 
                                         ? ds.Tables[0].Copy() : new DataTable();
                    }
                }
            }
        }
        catch
        {
            throw;
        }
    }

Upvotes: 0

PradeepGB
PradeepGB

Reputation: 314

Yes, It is possible. Create connection on DBF table as appropriate based on this link http://www.connectionstrings.com/dbf-foxpro. Later you get the entire data onto a Dataset. You can save data set wherever you want to in XML format.

Upvotes: 1

Related Questions