阅读从Visual Fox专业数据库中的数据用C# [英] Read data from Visual Fox Pro database with C#

查看:190
本文介绍了阅读从Visual Fox专业数据库中的数据用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做一个数据连接到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:\\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;
   }
}

这篇关于阅读从Visual Fox专业数据库中的数据用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆