Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Writing .dbf files from .NET
Message
De
09/04/2008 12:51:43
Dave Nantais
Light speed database solutions
Ontario, Canada
 
 
À
09/04/2008 11:38:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01309382
Message ID:
01309429
Vues:
8
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!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform