 |
 |

08-28-2006, 05:12 AM
|
 |
Centurion
|
|
Join Date: Jan 2004
Location: norway
Posts: 156
|
|
Help with Convert.ToDateTime(String) error
|
I'm just so confused here..
I run my application, do some stuff, call a sub which contains this line:
Code:
aParallel.StartDate = Convert.ToDateTime(stringReportStart)
...and everything works fine
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.
Please help
Code:
************** 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)
....
|
|

08-28-2006, 06:03 AM
|
 |
Contributor
* Expert *
|
|
Join Date: Jul 2003
Location: Leicestershire, England
Posts: 710
|
|
|
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.
|
|

08-28-2006, 06:25 AM
|
 |
Centurion
|
|
Join Date: Jan 2004
Location: norway
Posts: 156
|
|
|
well, this was the first thing i checked, and i can assure you, the data is indentical the first and second time. any other ideas?
|
|

08-28-2006, 07:22 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
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
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|