1

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?

Cylian
  • 10,970
  • 4
  • 42
  • 55
Muhammad Zeeshan
  • 8,722
  • 10
  • 45
  • 55

2 Answers2

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.

PradeepGB
  • 314
  • 2
  • 10
  • I have tried it but showing some errors that file path is not correct. – Muhammad Zeeshan Nov 04 '10 at 11:11
  • Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mypath;Extended Properties=dBASE IV;User ID=Admin;Password=; – Muhammad Zeeshan Nov 04 '10 at 11:11
  • Easiest way is to create a ODBC connection is possible and use the connection to fetch the data. – PradeepGB Nov 04 '10 at 11:14
  • OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Visual FoxPro Driver};" + "SourceType=DBF;" + "SourceDB=C:\\jobact.DBF;" + "Exclusive=No"; conn.Open(); It is showing the following error System.Data.Odbc.OdbcException ERROR IM001 Microsoft ODBC Driver Manager Driver does not support this function – Muhammad Zeeshan Nov 04 '10 at 12:53
  • http://www.eggheadcafe.com/community/aspnet/2/10029405/dbf-file-to-xml.aspx and http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/e56aa822-1dad-4745-a7d0-9af111a71f98 – PradeepGB Nov 04 '10 at 17:46
0

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;
        }
    }
famousKaneis
  • 302
  • 4
  • 18
matrix
  • 3,000
  • 3
  • 24
  • 35