by Jon Sagara
July 22, 2009 at 1:53 PM
Man, this is getting bad. See anything wrong with this?
INSERT INTO [dbo].[MyTable]
(
<snip />
[CreatedUtcDate],
[ModifiedUtcDate]
)
VALUES
(
<snip />
GETDATE(),
GETDATE()
)
by Jon Sagara
July 22, 2009 at 12:45 PM
Today's a good day. Check this out:
private static Dictionary<string, string> _dict = new Dictionary<string, string>();
static MyPage()
{
//_dict.Add("item1", "val1");
//_dict.Add("item2", "val2");
//_dict.Add("item3", "val3");
//_dict.Add("item4", "val4");
}
private void InitDictionary()
{
try
{
_dict.Add("item1", "val1");
_dict.Add("item2", "val2");
_dict.Add("item3", "val3");
_dict.Add("item4", "val4");
}//END TRY
catch
{
_dict.Clear();
_dict.Add("item1", "val1");
_dict.Add("item2", "val2");
_dict.Add("item3", "val3");
_dict.Add("item4", "val4");
}//END CATCH
}
So what happened here? The guy decided that initializing the static dictionary variable in the static constructor wasn't good enough, and that he needed to do it on every page request, so he created an instance method to do the initialization. For some reason, though, he kept getting an exception when initializing the dictionary after the first page view. Hmm... bettter just swallow the exception, clear the dictionary, and try again.
*slaps forehead*
by Jon Sagara
July 22, 2009 at 9:54 AM
Just ran across this awesomeness today:
string campaignId = null;
/* ------------------------------------------------------------------------
* see if the campaign id is in the request query params, so that a default
* based on the url can be set.
*/
foreach (object key in Request.Params)
{
string objCampaign = Convert.ToString(key);
if (string.Compare(objCampaign, "campaignid", true) == 0)
{
campaignId = Request[Convert.ToString(objCampaign)];
break;
}//END IF
}//END FOREACH
/* ---------------------------------------------------------------------- */
Huh. Well, that's one way to do a Request.QueryString["campaignid"] lookup.