C# Read and convert dbf file to xml

十年热恋 提交于 2019-12-11 06:57:52

问题


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?


回答1:


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.




回答2:


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;
        }
    }


来源:https://stackoverflow.com/questions/4095277/c-sharp-read-and-convert-dbf-file-to-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!