如何使用 .NET 从现有 VFP (OLEDB) 表创建新的 VFP (OLEDB) 表?

发布于 2024-08-10 17:40:59 字数 486 浏览 6 评论 0原文

我们有一个创建许多 Visual Foxpro (DBF) 表的应用程序。每个表都有不同的架构,但它们都包含一个已知的日期字段。

我被要求创建另一个应用程序(在 C# 中),它将上周的数据从每个表复制到一个新表(在与源表不同的文件夹中)。不同的表将保留(例如,如果存在三个源表,则将存在三个目标表)。

随着时间的推移,表可能会发生变化(例如添加新字段),因此我无法对表结构做出假设(除了上述日期字段的存在)。

从一个表中获取数据并创建具有相同结构的新表的最简单/最佳方法是什么?

我知道如何查询表以提取数据(例如,用上周的记录填充数据集)。但是,我认为必须有一种更好的方法来创建新表并用结果填充它,而不是手动解析架构中的所有字段信息并使用它来重新创建目标表。

使用 FoxPro 似乎与 SQL Server 不同,每次都让我头疼,所以我需要一些关于我的方法的指导。

生产机器上安装了 VFP 9 OLEDB 驱动程序。如果可能的话,我们不希望安装太多其他东西。

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

I've been asked to create another application (in C#) that will copy the last week's worth of data from each table to a new table (in a different folder to the source tables). The distinct tables will remain (e.g. if there are three source tables, there will be three destination tables).

Over time the tables may change (e.g. new fields added), so I can't make assumptions about table structure (apart from the existence of the aforementioned date field).

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

I know how to query the tables to extract the data (e.g. fill a DataSet with the last week's records). However, I'm thinking there must be a better way of creating a new table and filling it with the results than manually parsing all the field information in the schema and using that to recreate the the destination table.

Working with FoxPro seems to be different enough from SQL Server to give me a headache at each turn, so I need some guidance on my approach.

The production machine has the VFP 9 OLEDB driver installed on it. If possible, we'd prefer not to have to install much else.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离旧人 2024-08-17 17:40:59

要获得数据、表和记录的精确副本,您可以通过单个 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 引擎将结果集创建为新表,因此无需显式声明类型、列等,从一个查询数据并将其推入另一个...需要

考虑的一个问题...验证用户访问权限,以便明显能够在您尝试的任何位置创建、读取、写入创建新表。如果需要,您甚至可以指定完全限定的路径,例如 C:\SomeOtherPath\Monthly\MyTable1...

To get an exact copy of the data, table, and records, you can do via a single SQL-Select via

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();

Your where clause could be almost anything, and the Into TABLE clause tells the VFP engine to create the result set AS A NEW TABLE, so no need to explicitly declare types, columns, etc, query data from one and push into another...

One issue of consideration... Verify the user access to obviously be able to create, read, write wherever you are trying to create the new table. You can even specify a fully qualified path, such as C:\SomeOtherPath\Monthly\MyTable1 if need be...

老娘不死你永远是小三 2024-08-17 17:40:59

尝试这样的事情(用 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(); 
    } 
} 

Try something like this (note written in VB.NET and converted use 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(); 
    } 
} 
☆獨立☆ 2024-08-17 17:40:59

您可以简单地执行:

select * from myTable into table newTable [database dbName]

如 DRapp 所示。但是,您可能还想获取索引(如果有)(顺便说一句,不直接支持通过 VFPOLEDB 创建索引,但您可以使用 ExecScript() 函数来执行此操作)。那么最简单的方法是复制表的 DBF、CDX(和 FPT)文件。 VFP 是基于文件的。

You can simply do a:

select * from myTable into table newTable [database dbName]

as DRapp showed. However you may want to get indexes as well (if any) (BTW creating indexes via VFPOLEDB is not supported directly but you can do so using ExecScript() function). Then the easiest would be to copy the table's DBF, CDX (and FPT) files. VFP is file based.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文