I have a new laptop at work and code that worked earlier in the week does not work today.
The code that worked before is, simplified:
while (dr.Read
A possible explanation:
Basically, the problem was the sPositiveSign value under HKEY_CURRENT_USER\Control Panel\International being set to 0, which means the positive sign is '0'. Thus, while parsing the "positive sign 0" is being cut off and then the rest of the string ("") is parsed as a number, which doesn't work of course. This also explains why int.Parse("00") wasn't a problem. Although you can't set the positive sign to '0' through the Control Panel, it's still possible to do it through the registry, causing problems. No idea how the computer of the user in the post ended up with this wrong setting...
Better yet, what is the output of this on your machine:
Console.WriteLine(System.Globalization.NumberFormatInfo.GetInstance(null).PositiveSign);
I'm willing to bet yours prints out a 0
... when mine prints out a +
sign.
I suggest checking your Control Panel > Regional and Language Options
settings... if they appear normal, try changing them to something else than back to whatever language you're using (I'm assuming English).
This is way out of left field, but check your localization settings. I had a number of "input string was not in a correct format" when I moved a web site to a Canadian server. The problem was in a DateTime.Parse method, and was fixed by setting the culture to "en-US".
Yes, your situation is different — but hey, you never know.