Angel Princess

Angel Princess

  • NA
  • 100
  • 47.1k

How to replace existing ms access database with c# code?

Aug 24 2015 7:11 AM
String baseDirectory = @"F:\Backup";
String mdbSourceFilePath = @"D:\Db\abc.mdb";
String mdbTargetFileName = "abc.mdb";
String fullDirectory = Path.Combine(baseDirectory, DateTime.Today.ToString("dddd"));
if (!Directory.Exists(baseDirectory))
Directory.CreateDirectory(baseDirectory);
if (!Directory.Exists(fullDirectory))
Directory.CreateDirectory(fullDirectory);
String mdbTargetFilePath = Path.Combine(fullDirectory, mdbTargetFileName);
File.Copy(mdbSourceFilePath, mdbTargetFilePath);
This is for backup of database. If I click on backup button this is creating backup database but if I click it again is is not overwriting existing database. I want to replace the existing database.

Answers (1)