Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Writing .dbf files from .NET
Message
From
09/04/2008 12:51:43
Dave Nantais
Light speed database solutions
Ontario, Canada
 
 
To
09/04/2008 11:38:54
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01309382
Message ID:
01309429
Views:
9
I think the machine will still require some kind of Foxpro OLE or ODBC driver for this connection string to work.

Basically you've got several kinds of objects interacting to work with data
"Connection", "SQL COmmand", "DataAdapter", and "DataSet".

Once you understand these objects, their methods and how they interact with each other working with VFP data is easy.

Here are a couple of simple examples...

public void UpdateData(DataSet ds)
{
// I wouldn't actually hard-code the connection string here, it should be in your config settings
string TestConnection = "server=(local);database=MyDataBase;uid=sa;pwd=MyPassword";

SqlCommand CommandObject1 = new SqlCommand();
CommandOjbect1.Connection = new SqlConnection(TestConnection);
dataAdapter1 = new SqlDataAdapter(CommandObject1);

dataAdapter1.InsertCommand = new SqlCommand("Insert into FoxCustomerTable (name, address) VALUES ( @AName, @AnAddress )", sc.Connection);
dataAdapter1.InsertCommand.Parameters.Add("@xyz", SqlDbType.Int, 8, "xyz");
dataAdapter1.InsertCommand.Parameters.Add("@abc", SqlDbType.VarChar, 50, "abc");


dataAdapter1.Update(ds);

//the record is now inserted
}


public void UpdateMyData(DataSet ds)
{
// I wouldn't actually hard-code the connection string here, it should be in your config settings
string TestConnection = "server=(local);database=MyDataBase;uid=sa;pwd=MyPassword";

SqlDataAdapter da = new SqlDataAdapter("select * from FoxCustomerTable", this.TestConnection);
SqlCommandBuilder sb = new SqlCommandBuilder(da);

da.Update(ds);


}


Play inside the VS2005/2008 interface and try experimenting with these examples.
Also, Kevin Macneish published some good simple examples of accessing Fox data.
I think his book is availabel on www.FoxCentral.Net.
try http://foxcentral.net/microsoft/NETforVFPDevelopers.htm

have fun!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform