void restoreButton_Click(object sender, System.EventArgs e)
{
string path = pathTextBox.Text;
string d ame = dbDropDownList.SelectedValue;
string restoreSql = "use master quot
restoreSql += "restore database @d ame from disk = @path quot
string pai = "use master;ALTER DATABASE Wy SET OFFLINE WITH ROLLBACK IMMEDIATE;ALTER DATABASE Wy SET ONLINE WITH ROLLBACK IMMEDIATE"
SqlCo ection co = new SqlCo ection(Co tr);
SqlCommand com1 = new SqlCommand(pai, co );
SqlCommand myCommand = new SqlCommand(restoreSql, new SqlCo ection(Co tr));
myCommand.Parameters.Add("@d ame", SqlDbType.Char);
myCommand.Parameters["@d ame"].Value = d ame;
myCommand.Parameters.Add("@path", SqlDbType.Char);
myCommand.Parameters["@path"].Value = path;
try
{
co .Open();
com1.ExecuteNonQuery();
co .Close();
myCommand.Co ection.Open();
myCommand.ExecuteNonQuery();
infoLabel.Text = "恢复成功!< r>已经把备份"+path+"恢复到数据库"
}
catch(Exception ex)
{
infoLabel.Text = "恢复失败!< r>出错信息如下:< r> quot; + ex.ToString();
}
finally
{
myCommand.Co ection.Close();
}
}

