473,778 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDateTime overflow when doing an data insert from webpage

347 Contributor
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 2047
mzmishra
390 Recognized Expert Contributor
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
7976
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 between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
1
1378
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)) lSqlCmd.Parameters("@startDate").Value = lTTState.startDate lSqlCmd.Parameters.Add(New SqlParameter("@endDate", SqlDbType.DateTime)) lSqlCmd.Parameters("@endDate").Value = lTTState.endDate
1
2056
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 ? -- Please, check my theSpoke: http://www.thespoke.net/MyBlog/dgroh/MyBlog.aspx
6
2878
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 i have to use for this. Please suggest if any idea regarding data transfer. Thanks Shiva Vrata Anand
3
2136
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 server is running and I use client as the windows XP I do not get this error. -- Mike
1
3946
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 void btnAddTime_Click(object sender, EventArgs e) { try {
9
2558
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: ABCDEF 1a2b3c as you can see there are two sections one letter sections and one alphanumeric section. the first is only 6 characters long and then a space and then a set of 6 alphanumeric charaters. If this is being entered into a text box/combo...
3
1766
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 PM. Is there is any possibility to send null or ""
15
1730
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 prevent this? Also, is there a better way to design an data entry web page without using tables, (it's a realy paint in you know what to do that with tables), but I don't know how to line up the fields any other way. Thank You
4
3944
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
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9465
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.