Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Remove a piece of code after a number of execution?
  2. var con = InitializeDB.StartConnection(); // start the connection
  3. var cmd = con.CreateCommand();
  4. var cmdOther = con.CreateCommand();
  5. // check if its the first run of the software
  6. #region onlyUsefulForFirstTime
  7. cmd.CommandText = "SELECT Count(*) FROM Misc WHERE ItemName='FirstRun'"
  8. if (Int32.Parse(cmd.ExecuteScalar().ToString()) == 0)
  9.     // it is the first run, add the entry
  10.     cmd.CommandText = "INSERT INTO Misc(ItemName, Val) VALUES('FirstRun'," +  DateTime.Now + ")";
  11. else
  12. #endregion
  13.     // it is not the first run
  14.     cmd.CommandText = "SELECT Val FROM Misc WHERE ItemName='LastRun'";
  15.     cmdOther.CommandText = "SELECT Val FROM Misc WHERE ItemName='FirstRun'";
  16.     // now after this, we compare the value of LastRun and the date in FirstRun, if it's more than a month, we take the steps to backup the database
  17.        
  18. if (Properties.Settings.Default.alreadyExecuted == false)
  19. {
  20.      // run one-time code.
  21.  
  22.      Properties.Settings.Default.alreadyExecuted = true;
  23.      Properties.Settings.Default.Save();
  24. }