Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2005, 06:25 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pls help me!

Hi, i get the following error, but i don't understand it.

Server Error in '/e-library' 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.

Source Error:


Line 221: SqlDataAdapter1.InsertCommand.Parameters("@Due_Dat e").Value = Borrow_Date.AddDays(14)
Line 222: 'SqlConnection1.Open()
Line 223: SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
Line 224: SqlConnection1.Close()
Line 225: End Sub


Source File: c:\inetpub\wwwroot\e-library\Borrow.aspx.vb Line: 223

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(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   e_library.Borrow.Loan(String Title_id, String Title) in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:223
   e_library.Borrow.DataGrid1_ItemCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:147
   System.Web.UI.WebControls.DataGrid.OnItemCommand(D ataGridCommandEventArgs e)
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Code:
 Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
        If e.CommandName = "Select" Then   'to select particular title
            Dim TitleID, Title As Label
            TitleID = e.Item.FindControl("lblTitleID")
            Title = e.Item.FindControl("lblTitle")

            Dim a As Boolean
            a = Search(Title.Text)
            If a = True Then
                Loan(TitleID.Text, Title.Text)
                Panel1.Visible = True
            Else
                Panel2.Visible = True

            End If
        End If
    End Sub

Protected Function Search(ByVal Title As String) As String
        Dim str = "SELECT * FROM [Library] WHERE Title = Title"
        Dim dr As SqlDataReader
        Dim SqlDataAdapter1 As New SqlDataAdapter
        Dim sSQL As New SqlCommand

        With sSQL
            sSQL.Connection = SqlConnection1
            sSQL.Connection.Open()
            sSQL.CommandText = str
            sSQL.CommandType = CommandType.Text
            dr = sSQL.ExecuteReader()
        End With

        If dr.HasRows Then
            While dr.Read
                quantity = dr("Quantity")
                dr.Close()
                If quantity >= 1 Then
                    Return True
                Else
                    Return False
                End If

            End While
           dr.Close()
        End If 
 End Function

 Private Sub Loan(ByVal Title_id As String, ByVal Title As String)
        Dim Borrow_Date As DateTime
        Dim str1 = "INSERT Into LoanRecord Values (@Borrow_Date, @User_id," _
                                                       & "@Title_id, @Title, @Due_Date)"
        Dim InsCom As New SqlCommand(str1, SqlConnection1)
        SqlDataAdapter1.InsertCommand = InsCom
        SqlDataAdapter1.InsertCommand.Parameters.Add(New _
           SqlParameter("@Borrow_Date", SqlDbType.DateTime, 8))
        SqlDataAdapter1.InsertCommand.Parameters.Add(New _
           SqlParameter("@User_id", SqlDbType.Char, 10))
        SqlDataAdapter1.InsertCommand.Parameters.Add(New _
           SqlParameter("@Title_id", SqlDbType.Char, 10))
        SqlDataAdapter1.InsertCommand.Parameters.Add(New _
           SqlParameter("@Title", SqlDbType.VarChar, 100))
        SqlDataAdapter1.InsertCommand.Parameters.Add(New _
           SqlParameter("@Due_Date", SqlDbType.DateTime, 8))

        SqlDataAdapter1.InsertCommand.Parameters("@Borrow_Date").Value = DateTime.Today
        SqlDataAdapter1.InsertCommand.Parameters("@User_id").Value =  Session("UserID")
        SqlDataAdapter1.InsertCommand.Parameters("@Title_id").Value = Title_id
        SqlDataAdapter1.InsertCommand.Parameters("@Title").Value = Title
        SqlDataAdapter1.InsertCommand.Parameters("@Due_Date").Value = Borrow_Date.AddDays(14)
SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
        SqlConnection1.Close()
    End Sub
Can somebody help me? Thanks a lot!

Irene


 
Old June 8th, 2005, 06:55 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have only declared the variable Borrow_Date and
not set the value

 
Old June 8th, 2005, 09:01 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But I set the value of Borrow_Date to DateTime.Today already,
Is it enough?



 
Old June 9th, 2005, 07:57 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have set the value for the input paramter to the sql paramater.
But what about this line :

SqlDataAdapter1.InsertCommand.Parameters("@Due_Dat e").Value = Borrow_Date.AddDays(14)

Where is the value for Borrow_Date coming from?

 
Old June 9th, 2005, 07:59 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh! i meant to say :
You have set the value for the input parameter to the sql query.


 
Old June 9th, 2005, 09:02 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now i set the Borrow_Date = DateTime.Today before the sqlcommand,
so I don't get the error anymore. Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
pls help me.. nilusharief003 ASP.NET 2.0 Professional 5 December 4th, 2008 08:05 AM
Pls help me!! hoailing22 ASP.NET 1.0 and 1.1 Basics 4 June 10th, 2005 11:24 PM
Pls help me hoailing22 ASP.NET 1.0 and 1.1 Basics 3 May 24th, 2005 11:08 AM
Pls!!! I need your Help!!! Ariel ASP.NET 1.0 and 1.1 Basics 3 May 9th, 2005 06:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.