Here is a sample on how to access vfp stored procedure inside .Net.
This example is using OLEDB provider for accessing VFP stored procedure in .Net.
Create a test.dbc database inside your local drive say "D:"
CD d:\
CREATE DATABASE test.dbc
SET DATABASE TO TEST
CREATE TABLE login(userName c(20),age n)
Then edit stored procedure and add new procedure:
PROCEDURE vfpInsertProc
LPARAMETERS tcName, tnAge
INSERT INTO login values(tcName,tnAge)
ENDPROC
put the following code in any button's click on your C# form.
string str;
str = "Provider=vfpoledb.1;Data Source=d:\\test.dbc";
// the aboce line can be re-written as
//str = @"Provider=vfpoledb.1;Data Source=d:\test.dbc";
OleDbConnection conn = new OleDbConnection();
conn = new OleDbConnection(str);
// you need to inculde the following line in try - catch block
conn.Open();
MessageBox.Show(conn.State.ToString());
if (conn.State == ConnectionState.Open) // check if connection is opened
{
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "vfpInsertProc";
cmd.Parameters.Add("tcName","Singh");
cmd.Parameters.Add("tnAge",27);
//cmd.CommandTimeout = 30;
cmd.ExecuteNonQuery();
conn.Close(); //close the connection
}
Run your form and check table login in foxpro for newly added record from C#.net and it will help you to access vfp stored procedure in .Net
|
| Author: Kapil Dhawan 18 Jun 2008 | Member Level: Gold Points : 2 |
Hello Nice piece of code Thanks for sharing your knowledge with us. I hope to see more good code from your side This code will help lots of guys Thanks to you Regards, Kapil
|