Can anyone tell me how to obtain a list of tables in a Visual FoxPro database from within C#?
I tried using the GetSchema
but the information that comes back seems to just be counts (and not accurate counts at that).
Here is what I have...
string connSrc = @"Provider=VFPOLEDB.1;Data Source=myvfpdb.dbc";
using (var cmdSrc = new OleDbCommand())
using (var dbconnSrc = new OleDbConnection(connSrc))
{
dbconnSrc.Open();
DataTable schema = dbconnSrc.GetSchema();
}
I thought there might be some way I could open the dbc file directly and run a SELECT against it but the problem is the database is located in the path to the connection string. I could find no OleDb command that would extract the schema information.
EDIT:
I found a way that works but it seems a little clunky. Anybody know of a better way?
string connSrc = @"Provider=VFPOLEDB.1;Data Source=myvfpdb.dbc";
using (var conn = new OleDbConnection(connSrc))
dbc = conn.DataSource;
string path = Path.GetDirectoryName(dbc);
string database = Path.GetFileName(dbc);
using (var conn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=" + path))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM " + database;
DbDataReader reader = cmd.ExecuteReader();
}
}
EDIT:
With Tamar's suggestion changed the query statement to this...
cmd.CommandText = $"SELECT ObjectName FROM {database} WHERE ObjectType = \"Table\"";