This class is a wrapper round an oledb connection to FoxPro. Don't know if there's much need for one, but I've had need for it on several occasions allready ;-)
FoxPro needs a set of specific tweaks to make it work with the default bindings and especially if you want to update, simply using the default data adapter won't work out of the box.
The class uses the default .net OleDB providers, but the machine the code is used on will need to have the FoxPro provider installed. The VFPOLEDB can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyId=E1A87D8F-2D58-491F-A0FA-95A3289C5FD4&displaylang=en
The code of the connection class: Source Code
Usage is straight forward, create a connection. For example to connect to a folder:
FoxProConnection conn = new FoxProConnection(”c:\yourdatabasefolder”);
Of course instead of the folder, you can also use a dbc file. To get data out of an sql string, you can simply use the GetData commands. These will return a QueryResult object rather than the table directly. The advantage of this, is that you can use that object to update later on. If you don't need it, simply read out the Table property to get the table. Example:
conn.GetData(”select * from DbfName”);
To update, you have the choice to use the UpdateData method of the connection object, or to use the returned QueryResult object to update. An example of the latter:
QueryResult data = conn.GetData(”select * from table1”);
//you could also .net binding, for example: DataGridView1.DataSource =data;
//...some edits to the data.Table here
data.Update();
The above will work fine if the table has got a primary key set. In case it has not, you'll have to indicate which field(s) is the primary. This can also be doen with the queryresult object.
For example, using the data object from above and table1 having a field named “table1_key”, before the first update, set the keyfield:
data.SetKeyField(”table1_key”);