【发布时间】:2014-04-17 04:10:39
【问题描述】:
我需要使用 C# 连接到 Visual Studio 中的 .dbf 文件并填充数据表。有任何想法吗?我目前可以在 Visual Fox Pro 9.0 中查看表格
我尝试过但失败的代码,继续获取
外部表不是预期的格式。
private OleDbConnection conn;
private OleDbCommand cmd;
private OleDbDataReader dr;
private string sqlStr = "";
private DataSet myDataSet;
private OleDbDataAdapter myAdapter;
void test2()
{
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\PC1\Documents\\Visual FoxPro Projects\\;Extended Properties=DBASE IV;");
conn.Open();
sqlStr = "Select * from Clients.dbf";
//Make a DataSet object
myDataSet = new DataSet();
//Using the OleDbDataAdapter execute the query
myAdapter = new OleDbDataAdapter(sqlStr, conn);
//Build the Update and Delete SQL Statements
OleDbCommandBuilder myBuilder = new OleDbCommandBuilder(myAdapter);
//Fill the DataSet with the Table 'bookstock'
myAdapter.Fill(myDataSet, "somename");
// Get a FileStream object
FileStream myFs = new FileStream
("myXmlData.xml", FileMode.OpenOrCreate, FileAccess.Write);
// Use the WriteXml method of DataSet object to write XML file from the DataSet
// myDs.WriteXml(myFs);
myFs.Close();
conn.Close();
}
【问题讨论】:
-
数据表或数据集
-
有很多方法,但你需要展示你研究/尝试过的东西。您是否下载了 VFP OleDB 提供程序?调查过 OleDbConnection、OleDbCommand?
-
我已添加我的代码,但不断收到该错误。有什么想法吗?
-
由于其他人认为过于宽泛,但显然没有使用 VFP 的经验,因此建议搁置……见鬼。看看这个链接stackoverflow.com/questions/4107067/… 作为一个很好的起点来查询和获取正确的 VFP .net 提供程序......然后,查看关于 VFP 和参数化查询的其他答案
-
标签: c# datatable visual-foxpro dbf