Click here to Skip to main content
16,016,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,

I am calling a date field from sql to datatable and showing in a combobox.

Then i am using the following code to check the users selection in combobox and use it to get a related row value from datatable.

While i try to convert the selected item in combobox to date again for comparing in datatable, the above error occurs.

Pls suggest the wayout.

I have marked the line with error

Thanks

VB
Private Sub ddlDate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDate.SelectedIndexChanged

*****        Dim expenddt As Date = Date.ParseExact(ddlDate.SelectedItem, "dd-MM-yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)

        txtValue.Text = fnClosingvaluefromDatatable(expenddt)

    End Sub
Posted
Updated 15-Dec-17 1:31am
Comments
Richard MacCutchan 14-Mar-14 6:46am    
What is ddlDate?
atul sharma 5126 14-Mar-14 7:16am    
drop down list named ddldate in which i am listing the dates fetched from sql to datatable

1 solution

Please use cdate(ddldate.selecteditem) for comparing dates.


VB
Private Sub ddlDate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDate.SelectedIndexChanged
        Dim expenddt As Date = Date.ParseExact(ddlDate.SelectedItem, "dd-MM-yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)

        txtValue.Text = expenddt
        If Date.Today > CDate(ddlDate.SelectedItem) Then
            MsgBox("The current date is greater than of selected date")
        End If
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900