public void Restore(string duongdan, string database, string connectString, string dd_pro) { if (duongdan == String.Empty) { MessageBox.Show("Đường dẫn không được bỏ trống !", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { KetNoi_SQL con = new KetNoi_SQL(connectString); con.MoKetNoi(); string select = @"SELECT name FROM sys.databases Where name = '" + database + "'"; if (con.ExecuteScalar(select) != null) { string delete = @"DROP DATABASE " + database; con.ExecuteNonQuery(delete); } //string query = @"Backup Database " + database + " To Disk = N'" + duongdan + "'"; string query = @"restore database " + database + " from disk = N'" + duongdan + "'With Recovery"; con.ExecuteNonQuery(query); MessageBox.Show("Restore thành công"); } catch (Exception ex) { MessageBox.Show("Lỗi Restore !" + ex.Message, "Thất bại", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int soLuongDonVi() { int dem = 0; try { string sql = "select count(*) from DonViDoiTac"; dem = (int)kn.ExecuteScalar(sql); return(dem); } catch { return(dem); } }