C# Read and convert dbf file to xml

2019-08-10 07:51发布

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?

标签: c# xml foxpro
2条回答
smile是对你的礼貌
2楼-- · 2019-08-10 08:35

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;
        }
    }
查看更多
狗以群分
3楼-- · 2019-08-10 08:36

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.

查看更多
登录 后发表回答