
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.04 KB | hits: 6 | expires: Never
Remove a piece of code after a number of execution?
var con = InitializeDB.StartConnection(); // start the connection
var cmd = con.CreateCommand();
var cmdOther = con.CreateCommand();
// check if its the first run of the software
#region onlyUsefulForFirstTime
cmd.CommandText = "SELECT Count(*) FROM Misc WHERE ItemName='FirstRun'"
if (Int32.Parse(cmd.ExecuteScalar().ToString()) == 0)
// it is the first run, add the entry
cmd.CommandText = "INSERT INTO Misc(ItemName, Val) VALUES('FirstRun'," + DateTime.Now + ")";
else
#endregion
// it is not the first run
cmd.CommandText = "SELECT Val FROM Misc WHERE ItemName='LastRun'";
cmdOther.CommandText = "SELECT Val FROM Misc WHERE ItemName='FirstRun'";
// 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
if (Properties.Settings.Default.alreadyExecuted == false)
{
// run one-time code.
Properties.Settings.Default.alreadyExecuted = true;
Properties.Settings.Default.Save();
}