C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to access vfp stored procedure in .Net


Posted Date: 06 Jun 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Surinder SinghMember Level: Gold    
Rating: Points: 10



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




Responses

Author: Kapil Dhawan    18 Jun 2008Member 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



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: String To MD5 hash value
Previous Resource: Singleton design pattern
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use