gpt4 book ai didi

c# - 使用 C# 从 Visual Fox Pro 数据库中读取数据

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:52 27 4
gpt4 key购买 nike

我能够建立到 Visual Fox Pro 数据库的数据连接,我需要从它连接到 2 个表。我如何加入 2 个表然后在 C# 中检索数据?

最佳答案

首先,我会 download Microsoft's Visual FoxPro OleDb provider .

下载并安装后,您可以使用它连接到数据库表所在的 PATH。此外,如果应用程序使用的是正确链接表的“数据库”,您也可以明确包含数据库名称。

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

public class YourClass
{
public DataTable GetYourData()
{
DataTable YourResultSet = new DataTable();

OleDbConnection yourConnectionHandler = new OleDbConnection(
"Provider=VFPOLEDB.1;Data Source=C:\\SomePath\\;" );

// if including the full dbc (database container) reference, just tack that on
// OleDbConnection yourConnectionHandler = new OleDbConnection(
// "Provider=VFPOLEDB.1;Data Source=C:\\SomePath\\NameOfYour.dbc;" );


// Open the connection, and if open successfully, you can try to query it
yourConnectionHandler.Open();

if( yourConnectionHandler.State == ConnectionState.Open )
{
OleDbDataAdapter DA = new OleDbDataAdapter();
string mySQL = "select A1.*, B1.* "
+ " from FirstTable A1 "
+ " join SecondTable B1 "
+ " on A1.SomeKey = B1.SomeKey "
+ " where A1.WhateverCondition "; // blah blah...

OleDbCommand MyQuery = new OleDbCommand( mySQL, yourConnectionHandle );

DA.SelectCommand = MyQuery;

DA.Fill( YourResultSet );

yourConnectionHandle.Close();
}

return YourResultSet;
}
}

关于c# - 使用 C# 从 Visual Fox Pro 数据库中读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691556/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com