usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespacewindowsapplication4{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidBinddata (stringtable) { Try { stringstr = table. Substring (0, table. LastIndexOf ('\\')); using(System.Data.OleDb.OleDbConnection conn =NewSystem.Data.OleDb.OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data source="+Str+"; Extended properties=dbase IV; User id=admin; password=") {Conn. Open (); stringsql =@"SELECT * from"+ table. Substring (table. LastIndexOf ("\\")); System.Data.OleDb.OleDbDataAdapter da=NewSystem.Data.OleDb.OleDbDataAdapter (SQL, conn); DataTable DT=NewDataTable (); Da. Fill (DT); This. Datagridview1.datasource =dt. DefaultView; } } Catch(Exception ex) {MessageBox.Show (ex). Message); } } Private voidButton1_Click (Objectsender, EventArgs e) { This. Openfiledialog1.filename ="*. DBF"; if(Openfiledialog1.showdialog () = =DialogResult.OK) { This. Binddata ( This. Openfiledialog1.filename); } } }}
How to open DBF database files in C #