C# Fail to save row to datatable from FoxPro DBF

Deal all:
Followings are my code for connect to Foxpro DBF file.
It show me "external data table is not right format expected."
Could any help!
I thank you in advance.

using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
    {
String m_database = "CO01M.dbf";
String m_sqlStr = "select * from " + m_database+" where row=100";
String m_otherStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\VISW; Extended Properties=dBASE IV; User ID=Admin; Password=;";

        DataTable myDataTable = new DataTable();
        OleDbConnection m_ConnectTo1M = new OleDbConnection();
        m_ConnectTo1M.ConnectionString = m_otherStr;                                                                                   
        try
        { m_ConnectTo1M.Open();
          
          OleDbDataAdapter mDataAdpter = new OleDbDataAdapter(m_sqlStr, m_ConnectTo1M);              
          Console.WriteLine(@"Connect to J:\VISW\successfully!");
          Console.WriteLine("m_ConnectTo1M.Provider= "+m_ConnectTo1M.Provider);
          Console.WriteLine("m_ConnectTo1M.Database= "+m_ConnectTo1M.Database);
          Console.WriteLine("m_ConnectTo1M.DataSource= " + m_ConnectTo1M.DataSource);
          Console.WriteLine("m_ConnectTo1M.State= " + m_ConnectTo1M.State);
          DataSet myDataSet = new DataSet();
          mDataAdpter.Fill(myDataSet); //<<====Here is point error occured.
          //myDataTable = myDataSet.Tables[0];
          m_ConnectTo1M.Close();
          Console.WriteLine("m_ConnectTo1M.State= " + m_ConnectTo1M.State);
        }
        catch (Exception ex)
        { Console.WriteLine(ex.Message); }
    }
}

}
Screen Shot

4 answers

Try any of these values for the Extended Properties parameter in the connection string.

  • dBASE III
  • dBASE IV
  • dBASE 5.0

Dear max:
Thanks for your replying.
I replace provide 『Microsoft.Jet.OLEDB.4.0』with 『Microsoft OLE DB Provider for Visual FoxPro 9.0』. It couldn't work alone saving records to table.
I will try you suggestion on the morning of 18,Nov.2013.
Have you done that before ?
sincerely yours
tom

Did you get this to work? Please let us know if you found a solution.

Dear Max:
it is all done after copying hsp*.* from origin directory to test directory. I try to browse hsp.dbc and realized the reason why that is all about. hsp.dbc has information about what those dbf composite of and what type those fields are. I think FoxPro use hsp*.* files to manage dbf file. Nothing to do with drviers provider.
Now I concerned the speed of selecting data. It tooks 8 seconds to get this job done from selecting to display on console. I can't help thinking of the way FxoPro work with data selecting. I have to assign the order of index, then process query with right index key. There are no documents about how C# assigns the order of index( such as set order to ?).
I will Keep staying turn.
Sincerely yours
tom