c#讀取dbf檔案並輸出某一列
阿新 • • 發佈:2019-01-23
private void button1_Click(object sender, EventArgs e)
{
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\work\\test\\python\\extractopoints;Extended Properties=dBASE IV;User ID=Admin;Password=;";
string fileName = "E:\\work\\test\\python\\extractopoints\\1.dbf" ;
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);
foreach (DataRow theRow in ds.Tables[0].Rows)
{
Console.WriteLine(theRow["ID"]);
}
Console.WriteLine("success");
}