Results 1 to 4 of 4

Thread: Error 166 System.DateTime.TryParse(string, out System.DateTime)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Location
    CA, USA
    Posts
    81

    Error 166 System.DateTime.TryParse(string, out System.DateTime)

    Hi,

    I get this error when i write the following line of code:

    if (DateTime.TryParse(drow[dt.DateCol.Caption].ToString(), resub))

    this line executes well on another machine in our network which has the same version of framework as mine. but shows the following error in my machine.

    Error 166 The best overloaded method match for 'System.DateTime.TryParse(string, out System.DateTime)' has some invalid arguments

    Error 167 Argument '2' must be passed with the 'out' keyword

    please help me how to get rid of this

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Error 166 System.DateTime.TryParse(string, out System.DateTime)

    You have to put 'out' before the output variable.

    C# Code:
    1. if (DateTime.TryParse(drow[dt.DateCol.Caption].ToString(), out resub))
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Location
    CA, USA
    Posts
    81

    Re: Error 166 System.DateTime.TryParse(string, out System.DateTime)

    you are right.

    but the same syntax (without Out keyword) works fine on another machine and shows error in mine.

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

    Re: Error 166 System.DateTime.TryParse(string, out System.DateTime)

    My question is: why are you getting a date value as a string from a database at all? If you want to store date/time values in a database you should be storing them as binary date/time values in a date/time column. That way the database will return DateTime values to you and there's no need to parse at all.
    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

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