I need to import tables from foxpro 8.0 to sql server. How do I read the tables & schema from a foxpro directory/files in C# so I can create the tables in SQL Server and copy the data over?
Asked
Active
Viewed 7,263 times
3 Answers
8
You can accomplish this through the use of the GetSchema method on the OleDb.Connection class.
OleDbConnection connection = new OleDbConnection(
"Provider=VFPOLEDB.1;Data Source=.\\Northwind\\Northwind.dbc;"
);
connection.Open();
DataTable tables = connection.GetSchema(
System.Data.OleDb.OleDbMetaDataCollectionNames.Tables
);
foreach (System.Data.DataRow rowTables in tables.Rows)
{
Console.Out.WriteLine(rowTables["table_name"].ToString());
DataTable columns = connection.GetSchema(
System.Data.OleDb.OleDbMetaDataCollectionNames.Columns,
new String[] { null, null, rowTables["table_name"].ToString(), null }
);
foreach (System.Data.DataRow rowColumns in columns.Rows)
{
Console.Out.WriteLine(
rowTables["table_name"].ToString() + "." +
rowColumns["column_name"].ToString() + " = " +
rowColumns["data_type"].ToString()
);
}
}

jveazey
- 5,398
- 1
- 29
- 44
1
You can use ODBCConnection. I know foxpro is using .dbf files.
OdbcConnection Conn = new OdbcConnection("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=C:\\tbl.dbf;");
String SQL = "SELECT * FROM tbl.dbf";
Conn.Open();
OdbcCommand MyCommand = new OdbcCommand(SQL,Conn);
OdbcDataReader dr = MyCommand.ExecuteReader();
while (dr.Read())
{
//your code
}

NET Experts
- 1,525
- 17
- 35
-
I am not the downvoter, but right this wouldn't work with versions after VFP6. – Cetin Basoz Sep 18 '15 at 22:33
-
Visual FoxPro dbf is not the same as dBASE – Roel Nov 02 '15 at 14:30
-
the thing is this answers the question and not the version problem – NET Experts Nov 05 '15 at 06:26
-
this is correct for .dbf files. as per connection strings found here: https://www.connectionstrings.com/dbf-foxpro/ – JJ_Coder4Hire Aug 05 '16 at 13:46
1
With exception of the "Driver" providd by RJ's answer, go to MS and get the VFP OleDB provider... You might have compatibility issues if dealing with a database container.

DRapp
- 47,638
- 12
- 72
- 142