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