How to create a new VFP table (OLEDB) from an existing one using .NET?

We have an application that creates several Visual Foxpro tables (DBF). Each of these tables has a different schema, but they all contain a known date field.

I was asked to create another application (in C #) that will copy the data for the last week from each table to a new table (in a different folder in the source tables). Separate tables will remain (for example, if there are three source tables, there will be three destination tables).

Tables can change over time (for example, new fields are added), so I can’t make assumptions about the structure of the table (except for the presence of the specified date field).

What is the easiest / best way to take data from one table and create a new table with the same structure?

I know how to query tables to retrieve data (for example, populate a DataSet with records from last week). However, I think there should be a better way to create a new table and populate it with results than to manually parse all the field information in the schema and use it to recreate the destination table.

Working with FoxPro seems to be quite different from SQL Server to give me a headache at every turn, so I need to be guided by my approach.

The production machine has the VFP 9 OLEDB driver installed. If possible, we would prefer not to install much more.

+3
source share
3 answers

, , SQL-Select

OleDbConnection oConn = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=C:\\SomePath");
OleDbCommand oCmd = new OleDbCommand();
oCmd.Connection = oConn;
oCmd.Connection.Open();
oCmd.CommandText = "select * from SomeTable where someCondition into table YourNewTable";
oCmd.ExecuteNonQuery();         
oConn.Close();

where , Into TABLE VFP AS NEW TABLE, , .., ...

... , , , , , , . , C:\SomeOtherPath\Monthly\MyTable1, ...

+2

- (, VB.NET, www.developerfusion.co.uk/tools):

using System.Data.OleDb; 
using System.IO; 

static class Module1 
{ 
    public static void Main() 
    { 
        OleDbConnection oConn = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=C:\\"); 
        OleDbCommand oCmd = new OleDbCommand(); 

        { 
            oCmd.Connection = oConn; 
            oCmd.Connection.Open(); 
            // Create a sample FoxPro table 
            oCmd.CommandText = "CREATE TABLE Table1 (FldOne c(10))"; 
            oCmd.CommandType = CommandType.Text; 
            oCmd.ExecuteNonQuery(); 
        } 

        oConn.Close(); 
        oConn.Dispose(); 
        oCmd.Dispose(); 
    } 
} 
0

:

select * from myTable into table newTable [database dbName]

as shown by DRapp. However, you can also get indexes (if any) (BTW-creating indexes via VFPOLEDB is not directly supported, but you can do this using the ExecScript () function). Then the easiest would be to copy the tables DBF, CDX (and FPT) files. VFP is file based.

0
source

All Articles