It seemed like a good idea at the time...
-
Though I have no idea why I decided this would be the way I was going to do this. (Usage: Check the last time something was inserted into the database, and scan for new changes since that time)
Before:
var maxLastTouchedLookbackSql = new SqlCommand { CommandText = @"select isnull(max(creationtime), '1/1/1900') as maxLastTouched from some_database.dbo.some_table" }; var lastTouched = Database.GetQueryResults(Program.ApplicationServer, maxLastTouchedLookbackSql); var lastTouchedDate = new DateTime(); foreach (var row in from DataColumn column in lastTouched.Columns from DataRow row in lastTouched.Rows select row) { lastTouchedDate = DateTime.Parse(row[0].ToString()); }
After:
var maxLastTouchedLookbackSql = new SqlCommand { CommandText = @"select isnull(max(creationtime), '1/1/1900') as maxLastTouched from some_database.dbo.some_table" }; var lastTouched = Database.DatabaseWork.GetQueryResults(Data.Database.DatabaseWork.Some_Server, maxLastTouchedLookbackSql); var lastTouchedDate = DateTime.Parse(lastTouched.Rows[0]["maxLastTouched"].ToString());
Sigh. Good job, past me. You provided some ok site content.
-
Conceptualize what you're trying to accomplish, then write the code.
Not the other way around.