none
Read a .dbf RRS feed

  • Question

  • Hi folks,

    I have been trying without success to read the contents of a .dbf file into a datatable. It is a level 7 dbf.

    Using the following code I get error: "External table is not in the expected format."

    I got the code from a previous answer to a similar question.

    OleDbConnection conn;
    OleDbCommand cmd;
    OleDbDataReader dr;
    string sqlStr = "";
    DataSet myDataSet;
    OleDbDataAdapter myAdapter;
    
    conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Dir1\\Dir2\\;Extended Properties=DBASE IV;");
    conn.Open();
    sqlStr = "Select * from testdbf.dbf";
    //Make a DataSet object
    myDataSet = new DataSet();
    //Using the OleDbDataAdapter execute the query
    myAdapter = new OleDbDataAdapter(sqlStr, conn);
    //Build the Update and Delete SQL Statements
    OleDbCommandBuilder myBuilder = new OleDbCommandBuilder(myAdapter);
    
    //Fill the DataSet with the Table 'bookstock'
    myAdapter.Fill(myDataSet, "somename");
    // Get  a FileStream object
    FileStream myFs = new FileStream
                    ("myXmlData.xml", FileMode.OpenOrCreate, FileAccess.Write);
    // Use the WriteXml method of DataSet object to write XML file from the   DataSet
    //  myDs.WriteXml(myFs);
    myFs.Close();
    conn.Close();

    Any ideas ?

    J


    jppnn

    Friday, September 9, 2016 8:16 PM

Answers

All replies

  • Hi john pp nn,

    Since your problem is more related to ADO.NET Managed Providers, I will move it to ADO.NET Managed Providers Forum for support.

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 12, 2016 6:16 AM
  • Version 7 and higher of dBase are not supported by the Microsoft ISAM drivers. You would need a third party OLEDB or ODBC driver to connect to these versions.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, September 12, 2016 1:22 PM