However, the NEXT time this sub is called, with the EXACT same data input, an exception (described below) is throwed on the line above. Why? It worked the first time!?
If I exit the program and run it again - same thing; it works the first time, but next time it's all baluba.
************** Exception Text **************
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.GetDayOfNNN(DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
at System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.DateTime.Parse(String s)
at System.Convert.ToDateTime(String value)
Assumably the value of stringReportStart is being changed between the first running of the sub and the second running of the sub. If stringReportStart is not a valid DateTime then your code will crash.
it sounds like code somewhere else is modifying your date. (clearing it out or something like that.) If you're truely calling it with the exact same string, it won't error.
Are you using .NET 2.0 or 1.1? If you're using 2.0, Look at the DateTime.TryParse funciton. That will automatically wrap your conversion in a Try..Catch block. I would also use DateTime.Parse instead of Convert.ToDateTime() anyhow... (regardless of version.)
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned