Wednesday, March 21, 2012

Run time error: out-of-range datetime value

Hi everyone, this is the exception:

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

Here's my code!


... 'datagrid code
cmdSelect.CommandText = "SELECT * FROM [Table] WHERE [Date and Time] > '" & Me.tbFromDate.Text & "' AND [Date and Time] < '" & Me.tbToDate.Text & "'"
...

Me.tbFromDate.Text and Me.tbFromDate.text look like this: 27/11/2003 1:11:43 PM

The SQL Query works fine - just that this code gives a runtime error.

Can someone help?? I'm guessing I have to do somekind of conversion!!

AndrewDoes your sql query work fine with 27/11/2003 1:11:43 PM
or 11/27/2003 1:11:43 PM

While checking the date Try DateTime.Parse<your date>)

No comments:

Post a Comment