Import Data from FoxPro (DBF) database to DataGridView in C#

First add a browser control, TextBox, Button, and a DataGridView control on the form.
 
Form1.JPG
 
Add the following code in Button Click Event
  1. private void button1_Click_1(object sender, EventArgs e) {  
  2.     OpenFileDialog fdlg = new OpenFileDialog();  
  3.     fdlg.Title = "Select file";  
  4.     fdlg.InitialDirectory = @ "c:\";  
  5.     fdlg.FileName = txtFileName.Text;  
  6.     fdlg.Filter = "DBF Files(*.dbf)|*.dbf|All Files(*.*)|*.*";  
  7.     fdlg.FilterIndex = 1;  
  8.     fdlg.RestoreDirectory = true;  
  9.     if (fdlg.ShowDialog() == DialogResult.OK) {  
  10.         txtFileName.Text = fdlg.FileName;  
  11.         Import();  
  12.         Application.DoEvents();  
  13.     }  

Form2.JPG
 
When you select any DBF file from the Browser page then you get the full path of dbf file.
 
You will pass this path in the following function that will return the dbf file data in a dataset.
  1. public static DataTable GetDataTableDBF(string strFileName) {  
  2.     System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + System.IO.Path.GetFullPath(strFileName).Replace(System.IO.Path.GetFileName(strFileName), "") + ";Exclusive=No");  
  3.     conn.Open();  
  4.     string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";  
  5.     System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(strQuery, conn);  
  6.     System.Data.DataSet ds = new System.Data.DataSet();  
  7.     adapter.Fill(ds);  
  8.     return ds.Tables[0];  

You can easily show dataset data in Datagridview.
  1. DataTable dt = GetDataTableDBF(txtFileName.Text);  
  2. dataGridView1.DataSource = dt.DefaultView; 
Form3.JPG