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 28th, 2005, 05:30 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help me!

Hi, I have a datagrid to display data, that fulfills the selection criteria specified by user. When i run it, nothing is displayed. But when I debug, I get this error message in the catch section in private sub LoanRecord.

[error]
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
[/error]


Code:
    Private Sub LoanRecord()
        Dim a As New Common
        Dim con As New SqlConnection
        con = a.GetConnect()

        Dim str As String
        str = "Select * From LoanRec Where CategoryID =  '" & ddlCategory.SelectedValue & "' And Title LIKE '%" & txtTitle.Text & "%'" _ & " AND Borrow_Date Between '" & Calendar1.SelectedDate & "' AND '" & Calendar2.SelectedDate & "'"

        Dim SqlDataAdapter1 As New SqlDataAdapter(str, con)
        Dim ds As New DataSet

        Try
            SqlDataAdapter1.Fill(ds)
            DgLoan.DataSource = ds
            DgLoan.DataBind()

            If Not DgLoan.Items.Count = 0 Then
                DgLoan.Visible = True
            Else
                DgLoan.Visible = False
            End If

        Catch ex As Exception
            Dim b As String
            b = ex.Message

        Finally
            con.Close()
        End Try
    End Sub



    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If ddlView1.SelectedValue = "Loan Records" Then
            DgLoan.CurrentPageIndex = 0
            LoanRecord()
        ElseIf ddlView1.SelectedValue = "Waiting List Records" Then
            DgWaitingList.CurrentPageIndex = 0
            WaitingList()
        End If
    End Sub

    Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        txtStartDate.Text = Calendar1.SelectedDate
    End Sub

    Private Sub Calendar2_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar2.SelectionChanged
        txtEndDate.Text = Calendar2.SelectedDate
    End Sub

  Private Sub DgLoan_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
        Try
            DgLoan.CurrentPageIndex = e.NewPageIndex
            LoanRecord()
        Catch ex As Exception
            Dim a As String
            a = ex.Message
        End Try
    End Sub

Private Sub CustomValidator1_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        If ddlView1.SelectedValue = "Loan Records" Then
            If txtStartDate.Text = "" Or txtEndDate.Text = "" Then
                args.IsValid = False
            End If
        End If
    End Sub
Can somebody help me? Thanks a lot.

Irene

 
Old June 28th, 2005, 05:55 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Check the final structure of the generated SQL text. It sounds like the selected dates are set correctly which is causing the convertion in SQL to fail.

-Peter









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