[英]How do I read a Foxpro 8.0 database from c#?
I need to import tables from foxpro 8.0 to sql server. 我需要将表从foxpro 8.0导入到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? 如何从C#中的foxpro目录/文件中读取表和模式,以便在SQL Server中创建表并复制数据?
You can accomplish this through the use of the GetSchema method on the OleDb.Connection class. 您可以通过在OleDb.Connection类上使用GetSchema方法来实现此目的。
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()
);
}
}
You can use ODBCConnection. 您可以使用ODBCConnection。 I know foxpro is using .dbf files. 我知道foxpro正在使用.dbf文件。
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
}
除了RJ的答案提供的“驱动程序”之外,请转到MS并获取VFP OleDB提供程序......如果处理数据库容器,可能会遇到兼容性问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.