Re: 'String was not recognized as a valid DateTime



Error occured when openDate query string is not in the date format
(mm/dd/yyyy).

Please use try, catch between your code lines.
And check whether the _opendate variable is null before using it.

private DateTime _opendate;


try
{
_opendate = DateTime.Parse(Request.Form["openDate"]);
}
catch(FormatException ex)
{
_opendate = null;
}

if(_opendate!=null)
{
//Do what ever you want
}



Best regards,
sachintana-MCSD.NET


"Pial" zislam@xxxxxxxxx wrote in message
news:795114e5.0504200539.32a72af1@xxxxxxxxxxxxxxxxxxxxx
>I am facing problem in the following situation:
>
>
> I have a text box in the aspx file name: openDate. And my date format is
> mm/dd/yyyy.
>
> C#:
>
> private DateTime _opendate;
>
> _openDate = DateTime.Parse(Request.Form["openDate"]);
>
> I get error saying 'String was not recognized as a valid DateTime'
>
> thanks in advance
>
> Zahir


.


Loading