c#讀取dbf文件並輸出某一列

 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");
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章