我需要将表从foxpro 8.0导入到sql server.如何从C#中的foxpro目录/文件中读取表和模式,以便我可以在SQL Server中创建表并复制数据?
您可以通过在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() ); } }