Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data in a .dbf file using c#

Tags:

c#

dbf

How can I get the data in a .dbf file using c#??

What I want to do is to read the data in each row (same column) to further process them.

Thanks.

like image 849
user1484319 Avatar asked Jul 06 '12 06:07

user1484319


1 Answers

You may create a connection string to dbf file, then using OleDb, you can populate a dataset, something like:

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=directoryPath;Extended Properties=dBASE IV;User ID=Admin;Password=;";
using (OleDbConnection con = new OleDbConnection(constr))
{
    var sql = "select * from " + fileName;
    OleDbCommand cmd = new OleDbCommand(sql, con);
    con.Open();
    DataSet ds = new DataSet(); ;
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    da.Fill(ds);
}

Later you can use the ds.Tables[0] for further processing.

You may also check this article Load a DBF into a DataTable

like image 58
Habib Avatar answered Sep 17 '22 10:09

Habib