Sharing Mistakes

With VB 6 and ADO 2.x I can't tell you how many times I wrote the following type of code and only realized what I had done after I had pressed F5:


The Infamous Infinite Loop Blunder
'--- Using VB 6 and ADO 2.x
Do While Not oRs.EOF
    Debug.Print oRs(0)

Usually the moment after I ran this code I would realize that I was in an infinite loop. Then I would quickly put in the oRs.MoveNext just before the end of the loop and all would be well. Fortunately, in ADO.NET I no longer have this problem thanks to the DataReader and how it reads a record and moves the cursor to the next position all in one fell swoop. So .NET saved me from one of my most infamous blunders.


Using C# and ADO.NET
SqlDataReader oDr = oCmd.ExecuteReader();

But of course I didn't get off that easy. I now have all new mistakes to make with .NET. My most common mistake these days occurs when I declare a variable inside of a "try" block and then use it outside of the "try" block. For example, I'll do something along the lines of the foo method below:


Oops!public int foo(int y, int z)
        int x = y * z;
        // catch it here
    // this will not compile!
    return x;

But at least with this mistake I catch it when I build my C# project. Then I move the declaration of the variable x outside of the try block and all is well.

OK, so now that I have opened up and shared some of my embarassing blunders, it's time for you to share some of your common blunders. Don't be shy!

Tweet Post Share Update RSS

Hi, I'm John Papa. I author this blog, create courses for Pluralsight and am a Google Developer Expert and Microsoft Regional Director. I travel speaking at events and train technology thought leaders