in

ASP.NET Weblogs

Dave Burke - A freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

March 2004 - Posts

  • Julie Lerman is chasing away a cold

    Our pal Julie Lerman is chasing away a cold.  She's blaming it on some innocent child she encountered (briefly) at a local ski resort... 

    Anyway, this is serious because the MVP Summit is coming up and she has to be at her best to represent the Vermont .NET nerd contingent.  Maybe everyone should send her a picture of their kid to help lift her spirits?

    Get well soon, Julie!

     

  • Nuther good reason for Reflector

    I named a business object User.  It was UserConfig, but I liked the cleaner “User” name.  It didn't appear in a basic Ctrl-Shift intellisense check, so I thought I was okay. 

    Some days later I get a compile error with “User” in some namespaces not having a certain property.  Doing a search in Reflector showed me the appearance of “User” in several namespaces.

    I don't want to type the full namespace designation whenever I use it, so I'll go with...hm...UserInfo.  Let me check Reflector on that.

  • It's about basics

    I hadn't used the HtmlControls.HtmlInputFile control for a while, and was getting

    "Object reference not set to an instance of an object." 

    My form encryption type was correct, id name gibed, everything good.  Since everything was “right” I thought it might do a W2K3 thing. (Wouldn't be the first time...)  So a do a quick Existing Item copy to a W2K Server project and relaunch.  Same error.  Good!  Not a W2K3 issue. 

    Reviewing the code again I saw that I didn't declare my HtmlInputFile control as protected! 

    So I need to remember: when complexed, do a .NET 101 code check. 

  • On the slopes, no one knows you're a nerd

    I did “work work” during last night's usual latenight R&D session, so I took the hours and did some way end-of-season skiing at Bolton Valley, a resort 25 minutes from home base of Burlington, Vermont.  I enjoyed observing the guy in the pic who really knows how to relax on a ski lift, and the dog...this dog, it would run to the top of the mountain under the lift of its owner.  Then when the guy would ski down the mountain the dog would follow at top speed.  I watched it do this 3 times before I left to get some code time in.  What a dog!

    Then this afternoon at the end of worktime I biked quite a while just to say I skied and biked the same day.  I should probably cut out the latenight coding session tonight due to overexertion, but I've been enjoying a good run lately.  Learning a lot. 

    Back to writing code...

                     

     

  • Now a SQL DateTime man (no more SmallDateTime for me!)

    I mentioned the other night some dealings with using nullable value types in a SQL DateTime datatype.  I decided to go with my own date code for a condition, then null the value in the DL.  In this case I used '1/1/1869.' 

    But then I get the runtime:

    SqlDbType.SmallDateTime overflow. Value '1/1/1869 12:00:00 AM' is out of range. Must be between 1/1/1900 12:00:00 AM and 6/6/2079 11:59:59 PM.

    I've used SmallDateTime out of habit for years in setting up SQL field datatypes.  No more.  That's a pretty small time span when you think about it--not that we typically have a lot of use for 19th century dates, and I'm pretty sure I'll be dead in 2079 so I won't have to worry about updating my code, but still...

  • What I thought was a SQL bug

    When I hear guys talk about a bug in VS.NET or SQL Server or whatever, I'm always very skeptical.  I never conclude that the MS stuff I've used for years has bugs, but this was one of those times.  I also had the passing thought I had some data corruption, but it would have been the first time that happened with SQL Server since I began using it in 1996 with SQL Server 6.5.

    In my app I set a value in, lets say, ThisColumn to 'TBA' (or To Be Assigned.)  At a later stage in the app, via another wizard, the field is changed to NULL to indicate that assignment action was completed.  When I queried the table with “select * from table where ThisColumn <> 'TBA', the rows with NULL in ThisColumn did not appear.  (Hey, the value was NOT 'TBA!'  My problem was that because of the pattern of the data I was working with and what I was looking for, I had thought that only 3 specific rows were not appearing.

    It wasn't until just now while reviewing the process for this post 24 hours after the incident did I realize that NO rows with a null value were returned.  Man, I know null values are not retrieved in a string comparison query, but no matter how long I looked at that data it just didn't ring a bell.  That's what I get for doing “work work” at night. 

    damned embarrassing.

  • Panel display using z-index over Select controls. Ehhh! You lose!

    I wanted to simulate a popup window using a Panel as a sort of confirmation message box, but serverside and without javascript.  A Google post here by “crjunk” gave me the idea, and it worked GREAT!

    ...Oh, darn. Except for this little problem with Select boxes which don't use z-index.  So any panel I might wish to display is going to be eaten up with select boxes, like bricks in a wall.

    Isn't that special! 

    Here's a superb newsgroup thread on it, and the KB on z-index.

    Yet another thing to have to suckup and swallow about web application development.  Oh, I understand why things work this way with select boxes and z-index and all that, I just wasn't prepared for it tonight...

     

  • DBNull.Value and DateTime datatype, or, value types and reference types

    This is a bit of a sticky wickett I'm seeing, trying to store a DBNull.Value in a BusObject DateTime member for passing to the DL.  As in:

    useredit.birth_date = DataHelper.CheckNullString(txtBirthDate.Text); // CheckNullString returns DBNull.Value is txtBirthDate blank...

    Seems to boil down to types.  Helpful newsgroup post from Madhu on this subject I'll have to get back to...

  • StartsWith vrs. Substring(0,#)

    I revived an old .ASP function in C# to pass a clean phone number to the DL and happened upon String().StartsWith, a superior method to Substring(0,Some_Int):

    Lame

    if (phonenum.Substring(0,2) == "1-" || phonenum.Substring(0,2) == "1." || phonenum.Substring(0,2) == "1 " || phonenum.Substring(0,2) == "1(")

    Better

    if (phonenum.StartsWith("1-") || phonenum.StartsWith("1.") || phonenum.StartsWith("1 ") || phonenum.StartsWith("1("))

    Best

    Some regex expression... :-)

     

  • Conditional or Ternary Operators in C#

    You get hooked in C#:  how can I write this in less code?  How can I be more economical?

    I've used the ?: conditional operator occasionally over the last couple of years, but didn't take the time to “get it.“

    In short, it provides a one-time statement to replace an if(){} else {} sequence, like so:

    txtWork_phone.Text = ue.work_phone != string.Empty ? TextUtils.PrettyPhone(ue.work_phone) : string.Empty;

    instead of

    if (ue.work_phone != string.Empty)
    {
     txtWork_phone.Text = TextUtils.PrettyPhone(ue.work_phone);
    }
    else
    {
     txtWork_phone.Text = string.Empty;
    }

    A mistaken approach to using the Conditional Operator would be something like

    i < j ? i++ : j++;

    This produces the error:  Only assignment, call, increment, decrement, and new expressions can be
    used as a statement.

    k = i < j ? i++ : j++;

    The trick is in utilizing the initial assignment.  Cool C# tidbit for the day.  Big thanks to a newsgroup post authored by Jacob Yang helping me to happily get it.

More Posts Next page »