I want to read a simple foxpro dbf file and convert it into xml file and save it into my pc. Is it possible to read and convert simple file.DBF with out using any db connection?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, It is possible. Create connection on DBF table as appropriate based on this link http://www.connectionstrings.com/dbf-foxpro. Later you get the entire data onto a Dataset. You can save data set wherever you want to in XML format.
回答2:
Here is the code...
private void btnBrowse_Click(object sender, EventArgs e)
{
try
{
var path = "F:\\Projects\\dbf"; // Path of the folder containing dbf file.
var fileName = "Invoices1.dbf";
var constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=DBASE III";
var sql = "select * from " + fileName;
var ds = new DataSet();
using (var con = new OleDbConnection(constr))
{
con.Open();
using (var cmd = new OleDbCommand(sql, con))
{
using (var da = new OleDbDataAdapter(cmd))
{
da.Fill(ds);
dataGridView1.DataSource = ds.Tables.Count > 0
? ds.Tables[0].Copy() : new DataTable();
}
}
}
}
catch
{
throw;
}
}