Results 1 to 2 of 2
Mar 2, 2012, 09:59 #1
- Join Date
- Nov 2011
- 0 Post(s)
- 0 Thread(s)
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow in parameterized query
I am lost on the exception that I have getting thrown at me right now.
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
What I am trying to do on my site, which is Windows Authenticated on an internal network, is capture the users ID that is logged in, and then depending on which page(s) the user clicks, store them in a database.
This is the code to check if the users ID has been set, and to add the entry into the database via a parameterized query.
Initial Setting of Session for the UsersID
Dim LoggedIn As String = User.Identity.Name If LoggedIn.Contains("PARTNERS") Then Session("LoggedIn") = LoggedIn.Substring(9) Else Session("LoggedIn") = LoggedIn End If
Depending on which page they choose, I want to store that in a database that I have called tblView. HEre is the structure of the table.
ID : Integer : Primary Key, auto-incremented
InquiryID_fk : Integer : Foreign Key; the inquiry id that is being viewed or edited
Page : Varchar(10) : Will store either "View" or "Edit" depending on the page entered
User : varchar(10) : Stores the userID : which is a max of 6 characters
Date : Date : Want to store the system date
Time : Time(7) : want to store the system time
Here is the code in the "View" page to store into the db, which throws the error
Dim InquiryID As String = Request.QueryString("id") Dim InquirySQL As String Session("InquiryID") = InquiryID If Not Session("LoggedIn") Is Nothing Then Dim ViewSQL As String ViewSQL = "Insert into tblView(InquiryID_fk, Page, User, Date, Time)Values(@InqID, @Page, @User, @ActDate, @ActTime)" Dim querycommand As New SqlCommand querycommand.Connection = Conn With querycommand .CommandType = CommandType.Text .CommandText = ViewSQL .Parameters.AddWithValue("@InqID", Session("InquiryID")) .Parameters.AddWithValue("@Page", "View") .Parameters.AddWithValue("@User", Session("LoggedIn")) .Parameters.AddWithValue("@ActDate", Date.Today) .Parameters.AddWithValue("@ActTime", TimeOfDay) Conn.Open() .ExecuteScalar() Conn.Close() End With querycommand.Dispose() End If
Any help would be excellent, this has been pretty frustrating.
Thank you in advance,
Mar 2, 2012, 15:29 #2
- Join Date
- May 2003
- Washington, DC
- 3 Post(s)
- 0 Thread(s)
You really should just use a single field here, no need to break it up -- Sql's DateTime stores both just fine. Your TimeOfDay is probably just setting TimeOfDay but not the day, month or year so you end up with something outside of SQL's acceptable range.