C#
--
Questions
--
Followers
Top Experts
I'd like to read FoxPro 9.0 database from within a C# application.
I have installed
Microsoft Visual Studio Community 2019
Microsoft OLE DB Provider for Visual FoxPro 9.0 (https://www.microsoft.com/en-us/download/details.aspx?id=14839)
on a
Windows 7 64-bit OS
then rebooted it several times and created a C# console application ConsoleApp1
using System;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
DataTable MyResultSet = new DataTable();
var MyDbConn = new OleDbConnection(
@"Provider=VFPOLEDB;Data Source=C:\\Users\\cbbe\\Desktop\\pup\\data\\;"
);
Console.WriteLine("Hello World!");
}
}
}which fails to run because of an error
Severity Code Description Project File Line Suppression State
Error CS1069 The type name 'OleDbConnection' could not be found in the namespace 'System.Data.OleDb'. This type has been forwarded to assembly 'System.Data.OleDb, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Consider adding a reference to that assembly. ConsoleApp1 C:\Users\cbbe\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 12 Activeand now when I go to the Project -> Add COM reference... there is
No Items found for search term(s): 31bf3856ad364e35
No Items found for search term(s): oledb
No Items found for search term(s): 4.0.1.0
and when I type "ole" in the search field there is a
ctv OLE Control module
Microsoft OLE DB Provider for Visual FoxPro 7.0 Type Library
Microsoft OLE DB Service Component 1.0 Type Library
Microsoft OLE DB Simple Provider 1.5 Library
OLE Automation 2.0
OLE Automation 1.0
OLE DB Errors Type Library
oleprn 1.0 Type Library
which keeps me guessing:
1.
Where is the Microsoft OLE DB Provider for Visual FoxPro 9.0 I have installed earlier?
2.
What COM libraries should I link to my ConsoleApp1 to be sure I'm using the FoxPro 9.0 compatible OLE provider?
3.
Where can I find a decent documentation for all these wonderful linkable components?
Thank you for your patience reading this. There's also a screenshot illustrating my problem.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
No extra COM libraries are necessary, .NET knows where to look for the driver it it is installed properly.
Documentation? Search the web for existing code samples. Intellisense can also help a lot.
Important here is the fact the VFPOLEDB provider is 32 bit only so you also need 32 bit .NET Framework components.
If you see the location of System.Data assembly in C:\Program Files (x86)\ folder which is derived for 32 bit applications then it should work.
Following code works for me w/o issues.
-saige-
Important here is the fact the VFPOLEDB provider is 32 bit only so you also need 32 bit .NET Framework components.This also means, that you need to select 32bit as target in the projects settings..






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
-saige-
-saige-

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
System.Data.OleDb.OleDbException: 'Function is not implemented.'on aMyAdapter.Fill(ds);line.But that not bothers me since I'm not sure I want to use the System.Data.OleDb at all. I was hoping to create an ActiveXObject("ADODB.Connection") object and then inspect it using debugger or something to see it's actual API interface (functions, objects, constants, etc.)
As far as I understand, System.Data.OleDb is a C#-specific package that doesn't exists outside of C# (I mean the API). Please correct me if I'm wrong.
using System;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApp4CoreVFPOLEDB
{
class Program
{
static void Main(string[] args)
{
//DataTable MyResultSet = new DataTable();
var MyDbConn = new OleDbConnection(
@"Provider=VFPOLEDB;Data Source=d:\\w7\\VFPApp\\Testy\\;"
);
MyDbConn.Open();
var MyAdapter = new OleDbDataAdapter("SELECT * FROM Orders", MyDbConn);
DataSet ds = new DataSet();
MyAdapter.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
Console.WriteLine("OrderID {0}, Shipping Zone: {1}",
ds.Tables[0].Rows[i].ItemArray[0], ds.Tables[0].Rows[i].ItemArray[28]);
}
Console.WriteLine("Total {0} order(s)", ds.Tables[0].Rows.Count);
Console.WriteLine("Hello World 2!");
//Console.ReadKey();
}
}
}then I believe you have your path and your table in the SELECT command.I am also using this project properties:

Imports System
Imports System.Data
Imports System.Data.OleDb
Module Program
Sub Main(args As String())
Dim connection = New OleDbConnection("Provider=VFPOLEDB;Data Source=C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind\;")
Dim adapter = New OleDbDataAdapter("SELECT FirstName, LastName from Employees", connection)
Dim ds = New DataSet()
adapter.Fill(ds)
For Each row In ds.Tables(0).Rows.Cast(Of DataRow)
Console.WriteLine($"{row("FirstName")} {row("LastName")}")
Next
Console.ReadLine()
End Sub
End ModuleProduces the following output:HTH,
-saige-






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
var dbconn = new OleDbConnection(@"Provider=VFPOLEDB;Data Source=C:\\Program Files (x86)\\Microsoft Visual FoxPro OLE DB Provider\\Samples\\Northwind\\;");
dbconn.Open();
var adapter = new OleDbDataAdapter("SELECT FirstName, LastName from Employees", dbconn);
DataSet ds = new DataSet();
adapter.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
Console.WriteLine("FirstName {0}, LastName: {1}",
ds.Tables[0].Rows[i].ItemArray[0], ds.Tables[0].Rows[i].ItemArray[1]);
}
Console.WriteLine("Total {0} record(s)", ds.Tables[0].Rows.Count);
Console.WriteLine("Hello World 4!");
Console.ReadKey();
}
}
}and printsC:\Users\cbbe\source\repos\ConsoleApp4\ConsoleApp4\bin\Debug>ConsoleApp4.exe
FirstName Nancy , LastName: Davolio
FirstName Andrew , LastName: Fuller
FirstName Janet , LastName: Leverling
FirstName Margaret , LastName: Peacock
FirstName Steven , LastName: Buchanan
FirstName Michael , LastName: Suyama
FirstName Robert , LastName: King
FirstName Laura , LastName: Callahan
FirstName Anne , LastName: Dodsworth
Total 9 record(s)
Hello World 4!there's something probably wrong with the query.
using System;
using System.Data;
using System.Data.OleDb;
using System.Linq;
namespace EE_Q29201752
{
class Program
{
static void Main(string[] args)
{
var connection = new OleDbConnection(@"Provider=VFPOLEDB;Data Source=C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind\;");
var adapter = new OleDbDataAdapter("SELECT FirstName, LastName from Employees", connection);
var ds = new DataSet();
adapter.Fill(ds);
foreach (var row in ds.Tables[0].Rows.Cast<DataRow>())
{
Console.WriteLine($"FirstName: {row["FirstName"]}, LastName: {row["LastName"]}");
}
Console.WriteLine($"Total {ds.Tables[0].Rows.Count} record(s)");
Console.ReadLine();
}
}
}Which produces the following output:-saige-

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
System.Data.OleDb is not C# specificso it's .NET Framework specific?
C#
--
Questions
--
Followers
Top Experts
C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).