Arun Lakshmanan
Arun Lakshmanan

Reputation: 1

Create temp table in Visual FoxPro from .NET

How to create a temporary Table in VisualFoxPro from .NET code using OLEDB connection?

Upvotes: 0

Views: 840

Answers (2)

Cetin Basoz
Cetin Basoz

Reputation: 23797

What exactly do you mean by a "temp" table? Do you need it to persist on disk even after you close it or really temporary and exists while you keep it open (with or without a disk persistence and unique to a connection)?

If you want to create a table that persists on disk and\or accessible by other users, then simply you can use a "create table ... (...)" SQL call. For example:

using (var con = new OleDbConnection(@"Provider=VFPOLEDB;Data Source=c:\temp"))
{
    var sql = @"create table myTemp free (
    id int,
    dummy char(10),
    when datetime
    )";
    con.Open();
    new OleDbCommand(sql,con).ExecuteNonQuery();
    con.Close();
}

Other type of "temp" table is known as "cursor" in VFP world and depending on your exact needs may be created differently or may not be needed at all (latter is the case generally). I don't know a direct way of creating that really. You may create it as a derived cursor, or generally you need to use a stored procedure in a database with "SetResultSet()" call.

Yet another way where you can "sort of" use VFP commands as if you are using VFP is to ExecScript() function with a bunch of code to execute. However, there are tons of commands and functions that work with ExecScript() if called from within VFP but they are not supported through VFPOLEDB. And unfortunately there is no correct list of unsupported and supported commands\functions (some listed as supported when in fact not and some are listed as unsupported while supported in fact - it is more of a trial and error and patience if you have enough).

If you can detail what you are trying to do exactly then the answer might be much simpler (or harder).

Upvotes: 0

Dhugalmac
Dhugalmac

Reputation: 574

One possible way (at least in VB.Net) would be to create a VFP Object (assuming that you have VFP installed on the workstation/server) and then use VFP 'Native' Commands.

For example:

Dim oVFP As Object
oVFP = CreateObject("VisualFoxPro.Application")
oVFP.DoCmd( <VFP Command1 goes here> )
oVFP.DoCmd( <VFP Command2 goes here> )
oVFP.DoCmd( <VFP Command3 goes here> )
' --- when done close VFP Object ---
oVFP.Quit()
oVFP = Nothing

Good Luck

Upvotes: 1

Related Questions