帮助看下winform中点击按钮备份数据库的问题,谢谢!
private void button2_Click(object sender, EventArgs e)
{
try
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string path = this.folderBrowserDialog1.SelectedPath;
string sql = string.Format("Backup database dbyizhi to disk = '{0}'", path+"\\"+"beifen");
//dbyizhi是mdb数据库名字,beifen是我打算给备份文件起的名字
OleDbConnection conn = new OleDbConnection(@"provider=Microsoft.ACE.OLEDB.12.0;
Data Source=F:\lift_manage_design\lift_manage_design\dbyizhi.mdb;Initial Catalog=dbyizhi;User ID=sa;pwd=sa");
conn.Open();
OleDbCommand command = new OleDbCommand(sql, conn);
command.ExecuteNonQuery();
//下面判断文件是否生成来确定是否备份成功
//还原是一样的.只是sql改成"RESTORE FILELISTONLY FROM DISK ='路径'"
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);