Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Constructing a datetime variable from listbox input


Message #1 by sg48@y... on Thu, 21 Nov 2002 03:51:03
I have an hour list box, a minute listbox and an ampm radiobuttonlist.
I would like to get the selectedvalues from these controls and construct a 
variable that I can input into a SQL2000 DB datetime field. So far what 
I've got is the code snippet shown below, but it doesn't work.

Dim strStartTime As String
strStartTime = ddlStartHour.SelectedItem.Text _
                    & ":" _
                    & ddlStartMinute.SelectedItem.Text _
                    & ":00"
                    & " " & ampm.SelectedItem.Text
Dim updatedstarttime As DateTime

updatedstarttime = FormatDateTime(TimeValue _   
(strStartTime),DateFormat.LongTime)

The browser error is:
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.

Source Error: 


Line 301:
Line 302:            myConnection.Open()
Line 303:            myCommand.ExecuteNonQuery()
Line 304:            myConnection.Close()
Line 305:
 

Source File: C:\PortalVBVS\PortalVBVS\Components\EventsDB.vb    Line: 303 

Stack Trace: 


[SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 
AM and 12/31/9999 11:59:59 PM.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +643
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +206
   ASPNetPortal.EventsDB.UpdateEvent(Int32 moduleId, Int32 itemId, String 
userName, String title, DateTime expireDate, String description, String 
wherewhen, DateTime eventDate, DateTime eventtime, Int32 durationindex, 
Int16 Filter3ID, String Filter3) in 
C:\PortalVBVS\PortalVBVS\Components\EventsDB.vb:303
   ASPNetPortal.EditEvents.UpdateBtn_Click(Object sender, EventArgs e) in 
C:\PortalVBVS\PortalVBVS\DesktopModules\EditEvents.aspx.vb:191
   System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +108
   
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Ra
isePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 
sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1263

 
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 21 Nov 2002 16:22:26 +1100
The error is not with the code you have below. The error is when you try to
put this date into your database.

I suggest you output (to the screen) the value of: updatedstarttime, as it
is probably not what you expect...

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <sg48@y...>
Subject: [aspx_beginners] Constructing a datetime variable from listbox
input


: I have an hour list box, a minute listbox and an ampm radiobuttonlist.
: I would like to get the selectedvalues from these controls and construct a
: variable that I can input into a SQL2000 DB datetime field. So far what
: I've got is the code snippet shown below, but it doesn't work.
:
: Dim strStartTime As String
: strStartTime = ddlStartHour.SelectedItem.Text _
:                     & ":" _
:                     & ddlStartMinute.SelectedItem.Text _
:                     & ":00"
:                     & " " & ampm.SelectedItem.Text
: Dim updatedstarttime As DateTime
:
: updatedstarttime = FormatDateTime(TimeValue _
: (strStartTime),DateFormat.LongTime)
:
: The browser error is:
: 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.
:
: Source Error:
:
:
: Line 301:
: Line 302:            myConnection.Open()
: Line 303:            myCommand.ExecuteNonQuery()
: Line 304:            myConnection.Close()
: Line 305:
:
:
: Source File: C:\PortalVBVS\PortalVBVS\Components\EventsDB.vb    Line: 303
:
: Stack Trace:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index