Guest User

Untitled

a guest
Aug 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. C# Open DBF file
  2. public override bool OpenFile(string fileName, string subFileName = "")
  3. {
  4.  
  5. OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(fileName) + ";Extended Properties=dBASE IV;User ID=;Password=;");
  6. try
  7. {
  8. if (con.State == ConnectionState.Closed) { con.Open(); }
  9. OleDbDataAdapter da = new OleDbDataAdapter("select * from " + Path.GetFileName(fileName), con);
  10. DataSet ds = new DataSet();
  11. da.Fill(ds);
  12. con.Close();
  13. int i = ds.Tables[0].Rows.Count;
  14. return true;
  15. }
  16. catch
  17. {
  18. return false;
  19. }
  20.  
  21. }
  22.  
  23. da.Fill(ds);
  24.  
  25. "Provider=VFPOLEDB.1;Data Source=" + FullPathToDatabase
  26.  
  27. OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:folder;Extended Properties=dBASE IV;User ID=;Password=;"); // give your path directly
  28. try
  29. {
  30. con.Open();
  31. OleDbDataAdapter da = new OleDbDataAdapter("select * from tblCustomers.DBF", con); // update this query with your table name
  32. DataSet ds = new DataSet();
  33. da.Fill(ds);
  34. con.Close();
  35. int i = ds.Tables[0].Rows.Count;
  36. return true;
  37. }
  38. catch(Exception e)
  39. {
  40. var error = e.ToString();
  41. // check error details
  42. return false;
  43. }
Add Comment
Please, Sign In to add comment