Results 1 to 3 of 3

Thread: [2005] Conversion error

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    3

    [2005] Conversion error

    Hi,

    I have an application that is working fine locally and at several other PCs.
    But there is one customer that is receiving the following error:
    Conversion from string "8/18/2008 09:05:00" to type 'Date' is not valid.

    The date looks fine to me but the weird thing is that i searched the code over and over and i couldn't find anyplace where I'm converting from a string to a date.
    And this problem is only appearing at only one of our customers.

    Might this be a framework related problem?
    Because I'm also getting another error:
    EventType clr20r3, P1 sharpdial.exe, P2 3.0.0.0, P3 48970884, P4 system, P5 2.0.0.0, P6 4333ae87, P7 2c0d, P8 114, P9 system.net.sockets.socket, P10 NIL.
    whose source is the .NET Runtime 2.0 Error Reporting.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Conversion error

    They presumably have their system set to display dates with the day first, followed by the month, i.e. "dd/MM/yyyy". Not everyone lives in the US. Far more countries use that format than "MM/dd/yyyy". This is why you should NEVER assume that dates or currency are in any specific format and you should NEVER rely on implicit conversions.

    You should avoid storing dates as strings at all if possible but, if you must, then you will need to write code that enforces whatever format you choose to store it in. If you are specifically storing dates as strings in "MM/dd/yyyy" format then you should use Date.ParseExact or Date.TryParseExact to convert to Date objects and specify that format string, ensuring that the string is interpreted that way regardless of the system's regional settings.

    Also, if you log exceptions in all your applications then you will have a call stack to show you exactly where an error occurred.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    3

    Re: [2005] Conversion error

    Thank you for your reply.

    I was converting from string to data but i didn't notice it.

    As for the logging, i was logging the exceptions' messages only. (Changed them now)

    We don't live in the US but most of our systems US-based, that's why we didn't have any problems with the other customers.

    And since the program has already been implemented, i'm just gonna parse the date for now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width