1
Answer

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

Angel Princess

Angel Princess

9y
453
1
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)