protected void FixButton_Click(object sender, EventArgs e) { string connectString = WebConfigurationManager.ConnectionStrings["AbleCommerce"].ConnectionString.ToString(); using (SqlConnection connection = new SqlConnection(connectString)) { connection.Open(); string sql = @"IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'ac_Orders' AND CONSTRAINT_NAME = 'ac_Users_ac_Orders_FK1') BEGIN ALTER TABLE ac_Orders DROP CONSTRAINT ac_Users_ac_Orders_FK1 END; ALTER TABLE ac_Orders ADD CONSTRAINT ac_Users_ac_Orders_FK1 FOREIGN KEY (UserId) REFERENCES ac_Users (UserId) ON UPDATE NO ACTION ON DELETE SET NULL"; using (SqlCommand command = GetCommand(connection, sql)) { command.ExecuteNonQuery(); } connection.Close(); FixPanel.Visible = false; ResultPanel.Visible = true; AdminLink.NavigateUrl = NavigationHelper.GetAdminUrl("Default.aspx"); } }