Example #1
0
 private void btnRead_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //string FileName = lstFiles.SelectedItem.ToString();
         string fileName   = txtPath.Text.Trim();
         string path       = fileName.Substring(0);
         int    separator  = path.LastIndexOf("\\", StringComparison.Ordinal);
         string dataSource = fileName.Substring(0, separator) + "\\";
         string file       = fileName.Substring(separator);
         int    separator2 = file.LastIndexOf("\\", StringComparison.Ordinal);
         string DBF        = file.Remove(separator2, 1);
         int    separator3 = DBF.LastIndexOf(".", StringComparison.Ordinal);
         // string DBF_Extension = DBF.Substring(Separator3);
         string dbfFileName = DBF.Remove(separator3, 4);
         //open the connection and read in all the airport data from .dbf file into a datatables
         cls.OleConnect(dataSource);
         string sql = "select * from " + dbfFileName;
         dt = cls.OleDbDataText(sql);
         if (dt.Rows.Count > 0)
         {
             btnWrite.IsEnabled = true;
         }
         dgvData.ItemsSource = dt.DefaultView;
         cls.OleDongKetNoi();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error + " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }