读者朋友:
您好,将“还原”按钮的代码替换如下:
if (textBox3.Text == "")
{
MessageBox.Show("请选择备份数据库文件的路径。");
return;
}
try
{
if (DataClass.MyMeans.My_con.State == ConnectionState.Open)
{
DataClass.MyMeans.My_con.Close();
}
SqlConnection Tem_con = new SqlConnection(DataClass.MyMeans.M_str_sqlcon);
Tem_con.Open();
SqlCommand SQLcom = new SqlCommand("use master restore database db_PWMS from disk='" + textBox3.Text.Trim() + "' with replace", Tem_con);
SQLcom.ExecuteNonQuery();
SQLcom.Dispose();
Tem_con.Close();
Tem_con.Dispose();
MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyDataClass.con_open();
MyDataClass.con_close();
MessageBox.Show("为了避免数据丢失,在数据库原还后将关闭整个系统。");
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}