Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# and COM
Message
From
26/08/2001 18:55:51
 
 
To
24/08/2001 07:23:14
Raymond Humphrys
Michigan Department of Community Health
Bath, Michigan, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00548530
Message ID:
00549295
Views:
18
>Is it possible to access a VFP table from a dll written using C#, that can
>pull records out of a table, delete them, and then pack the table?

Yes. Here is some C# code that calls a stored proc in a VFP database. (Thanks to Jim Nelson for helping me get the syntax straightened out.)
using System;
using System.Data;
using System.Data.OleDb;

namespace TestData
{
	/// <summary>
	/// Summary description for TestData.
	/// </summary>
	public class TestData
	{
		public TestData()
		{

			string myConnString = "Provider=VFPOLEDB.1;Data Source=C:\\TEMP\\DATA\\TASTRADE.DBC;Mode=Share Deny None;" +
				"Extended Properties=\"\";User ID=\"\";Password=\"\";Mask Password=False;" +
				"Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";
			
			OleDbConnection myConnection = new OleDbConnection(myConnString);

			string myCmd;
			myCmd = "DeleteOrder<b>()</b>" ; // Stored procedure that just deletes one record with  DELETE - SQL command. Note the parens.
			
			OleDbCommand myCommand = new OleDbCommand(myCmd,myConnection);

			myConnection.Open();

			int cmdResults = -1 ;
			
			// myCommand.CommandType = CommandType.StoredProcedure ;
			myCommand.CommandType = CommandType.Text ; // StoredProcedure does not work. ADO strips the parens off and VFP requires them.

			try
			{
				cmdResults = myCommand.ExecuteNonQuery(); // NonQuery since no SQL rows are returned
				
			} 
			catch(System.Data.OleDb.OleDbException e) 
			{
				Console.WriteLine("Error occured: " + e.Message);
			}
			finally
			{			
				myConnection.Close();
				Console.WriteLine("cmdResults " + cmdResults);
				Console.ReadLine();
			}
		}
		public static void Main()
		{
			TestData foo = new TestData();
		}
	}
}
My stored proc was simply:
PROCEDURE DeleteOrder
	SET ANSI OFF
	DELETE FROM ORDERs WHERE ORDER_ID = "     2" && Just testing concept.
	USE IN ORDERS
	USE ORDERS EXCLUSIVE 
	PACK
RETURN
ENDPROC
You might want to note the VFP help topic "Unsupported Visual FoxPro Commands and Functions." However, this is not, apparently, exhaustive. I had an error (feature not available) trying to use STRTOFILE().
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform