由网友(Who are you.)分享简介:我可以做一个数据连接到Visual Fox专业数据库,从中我需要2个表。我如何加入2表然后检索在C#中的数据?I am able to make a Data Connection to a Visual Fox Pro database, from it I need to 2 tables. How do I j...
我可以做一个数据连接到Visual Fox专业数据库,从中我需要2个表。我如何加入2表然后检索在C#中的数据?
I am able to make a Data Connection to a Visual Fox Pro database, from it I need to 2 tables. How do I join the 2 tables then retrieve the data in C#?
推荐答案
首先,我的下载微软的Visual FoxPro OLEDB提供。
一旦下载并安装,你可以用它连接到PATH其中数据库表的位置。此外,如果应用程序使用的是数据库,其中表的正确链接,您可以明确包含数据库的名称了。
Once downloaded and installed, you can use it for connecting to the PATH where the database tables are located. Additionally, if the app is using a "database" where the tables are properly linked, you can explicitly include the database name too.
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:SomePathNameOfYour.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;
}
}
相关推荐
最新文章