Wednesday, February 15, 2012

Error: SqlDateTime overflow !??

When I run my query

dr = Me.SqlComm_Chk_ATLGroup.ExecuteReader

it give me this error:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

This is my Query :

SELECT break_time, break_rep_no, break_type, break_user_id
FROM breaks
WHERE (break_date = @.p1) AND (break_group = @.p2) AND (break_time > @.p3) AND (break_time < @.P4)
ORDER BY break_time

This is the code

Dim dr As SqlClient.SqlDataReader

Me.SqlConn.Open()
Me.SqlComm_Chk_ATLGroup.Parameters(0).Value = #7/23/2004#
Me.SqlComm_Chk_ATLGroup.Parameters(1).Value = 0
Me.SqlComm_Chk_ATLGroup.Parameters(2).Value = #10:00:00 AM#
Me.SqlComm_Chk_ATLGroup.Parameters(3).Value = #2:00:00 PM#

dr = Me.SqlComm_Chk_ATLGroup.ExecuteReader

While dr.Read

End While

Me.SqlConn.Close()

Note : when I store the time in a string and display it it gives me 10:00:00 AM 1/1/0001 or something like that ?

Where is the problem?you dont need to wrap the date with #'s in sql server. just pass it in like a regular string with quotes.

hth|||I do this:

tfrom = "9:00:00 AM"
tTo = "2:00:00 PM"
.
.
.
.
.
Me.SqlComm_Get_ATLSchdl.Parameters(2).Value = tfrom
Me.SqlComm_Get_ATLSchdl.Parameters(3).Value = tTo

And it still gives me the same error

Server Error in '/ccs' Application.

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.|||I tried to do this:

Me.SqlComm_Chk_Group.Parameters(2).Value = tFrom.AddMinutes(59).ToLongTimeString
Me.SqlComm_Chk_Group.Parameters(3).Value = tTo.AddMinutes(-59).ToLongTimeString

It works but without retrieving any data, the masteries thing is when I open the Query builder it brings me all the data I want normally but when I use it in the code it's not worked......

I think maybe its something with the time format I sending with the parameters; because I have the same code exactly but it brings the time from SQL data base so it seems it's some thing with the time but I don't know what it's favorite time format and I think I send it the same but there is a bug or something ……..

Finally I'm thinking about send the time to an temporary data base and retrieving it again, I think this is my only solution I get tell now

What do you think?

No comments:

Post a Comment