473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

SqlDateTime overflow when doing an data insert from webpage

347 100+
I have the following web page:

Expand|Select|Wrap|Line Numbers
  1. mports System.Data.SqlClient
  2. Imports System.Data
  3.  
  4. Partial Class Default2
  5.     Inherits System.Web.UI.Page
  6.     Dim opnumber As String
  7.     Dim exceptiondate As DateTime
  8.     Dim stime As DateTime
  9.     Dim etime As DateTime
  10.     Dim hours As String
  11.     Dim minutes As String
  12.     Dim exceptioncode As String
  13.     Dim submittedby As String
  14.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  15.         opnumber = CType(Session.Item("opnumber"), String)
  16.         exceptiondate = CType(Session.Item("exceptiondate"), DateTime)
  17.         stime = CType(Session.Item("starttime"), DateTime)
  18.         etime = CType(Session.Item("endtime"), DateTime)
  19.         hours = CType(Session.Item("hours"), String)
  20.         minutes = CType(Session.Item("minutes"), String)
  21.         exceptioncode = CType(Session.Item("exceptioncode"), String)
  22.         submittedby = CType(Session.Item("submittedby"), String)
  23.  
  24.         opnumLabel.Text = opnumber
  25.         exceptdateLabel.Text = exceptiondate
  26.         starttimeLabel.Text = stime
  27.         endtimeLabel.Text = etime
  28.         hourdurLabel.Text = hours
  29.         mindurLabel.Text = minutes
  30.         codeLabel.Text = exceptioncode
  31.         approvedbyLabel.Text = submittedby
  32.     End Sub
  33.  
  34.     Protected Sub sqlsubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sqlsubmitButton.Click
  35.         InsertRow()
  36.     End Sub
  37.     Public Sub InsertRow()
  38.         Dim myConnectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxxx;"
  39.  
  40.         Dim myConnection As New SqlConnection(myConnectionString)
  41.         Dim commandText As String = _
  42.         "insert into Exceptions (employeenumber, exceptiondate, starttime, endtime, duration, code, approvedby) " & _
  43.         "values(@employeenumber, @exceptiondate, @starttime, @endtime, @duration, @code, @approved)"
  44.  
  45.         Using connection As New SqlConnection(myConnectionString)
  46.             Dim command As New SqlCommand(commandText, connection)
  47.  
  48.             command.Parameters.AddWithValue("@employeenumber", opnumber)
  49.             command.Parameters.AddWithValue("@exceptiondate", exceptiondate)
  50.             command.Parameters.AddWithValue("@starttime", stime)
  51.             command.Parameters.AddWithValue("@endtime", etime)
  52.             command.Parameters.AddWithValue("@duration", hours & " " & minutes)
  53.             command.Parameters.AddWithValue("@code", exceptioncode)
  54.             command.Parameters.AddWithValue("@approved", submittedby)
  55.  
  56.             Try
  57.  
  58.                 connection.Open()
  59.                 Dim rowsAffected As Integer = command.ExecuteNonQuery()
  60.  
  61.             Catch ex As Exception
  62.                 myerrormessageLabel.Text = ex.Message
  63.             End Try
  64.             thankyouLabel.Text = "Your Data Has Been Submitted"
  65.         End Using
  66.  
  67.     End Sub
  68.  
  69.     Protected Sub cancelinputButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cancelinputButton.Click
  70.         Response.Redirect("Default.aspx")
  71.     End Sub
  72.  
and when I try to submit my data (which is):
Op #: 8451
Exception Date: 11/15/2010
Start Time: 11:00:00 AM
End Time: 12:00:00 PM
Duration: 1 hours 0 minutes
Reason: Approved Technical Reason
Submitted By: User

to my sql server, I get the following error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Can anyone tell me what may be causing this error?

Thank you,

Doug
Oct 17 '10 #1
1 2019
mzmishra
390 Expert 256MB
This exception comes if datetime value is null.
Check u r parameter values.
Oct 18 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: FrodoBaggins | last post by:
Dear Team, Attempting to insert a record into a SQL database, using the command: command.ExcuteNonQuery(); Get the following error message in the event log: SQLDateTime overflow. Must be...
1
by: poppy | last post by:
I set up my parameters in code as follows : lTTState.startDate = Today.AddDays(-10) lTTState.startDate = Today lSqlCmd.Parameters.Add(New SqlParameter("@startDate", SqlDbType.DateTime))...
1
by: Paperback Writer | last post by:
I need to insert null in a DateTime field and in the ASP.Net i got this error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. How to accomplish that ?...
6
by: shivavrata | last post by:
Hi All, I want to transfer the data form webpage to any other own application which is running in backend.How i develop this web page. which technology is good for this or any particular protocol...
3
by: Mike9900 | last post by:
Hello, I am getting SqlDateTime overflow if I use .NET remoting on Windows XP and Windows XP is the server where the SQL server is located at. If my computer is Windows 2003 where the sql...
1
by: lairpr | last post by:
I am having this kind of error when trying to insert a null value; SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. bellow is my code, thanks protected...
9
by: nerd19 | last post by:
I was wonder how i would go about limiting a length of a string that is going to be entered into a text box. An example my explain this better: the data is coming from a barcode that reads: ...
3
by: baburk | last post by:
HI I want to pass null or "" When I pass like that I got an error System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59...
15
by: Peter | last post by:
I have the following web page and I am trying to have the Field lables NOT to wrap. It looks fine in a designer but when I run the program in a browser the lables that have a space wrap. How do I...
4
by: jhansi xavier | last post by:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.