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
Re: Error 166 System.DateTime.TryParse(string, out System.DateTime)
You have to put 'out' before the output variable.
C# Code:
if (DateTime.TryParse(drow[dt.DateCol.Caption].ToString(), out resub))
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.
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.