Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter by Date

Status
Not open for further replies.

M444

Programmer
Feb 24, 2004
76
0
0
US
Hi All,

I am trying to filter a dataview by a user defined date...

When I attempt this I get the following error:

"Cannot perform '<' operation on System.DateTime and System.Double."

Here is my code:

Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
Dim SelectedDate As System.DateTime
SelectedDate = txtSelectedDate.Text
DV.RowFilter = "[Start_Date] < " & SelectedDate & " AND [End_Date] > " & SelectedDate
DataList.DataSource = DV
End Sub

Anyone know what I am doing wrong?
 
Make sure start_date and end_date are datetime columns. Also make sure what you enter in txtSelectedDate is a valid date.

Jim
 
Jim thanks for your post.

start_date and end_date are both DateTime columns and txtSelectedDate is being verified as a valid date.

So I still have the problem... Any other ideas?

I do not understand why it would think my declared datetime is of datatype System.Double
 
Code:
Dim dt As DataTable
Dim SelectedDate as Date = Date.TryParse(txtSelectedDate.Text)
dt = DV.Copy()
dt.DefaultView.RowFilter = "Start_Date < " & SelectedDate & " AND End_Date > " & SelectedDate
DV.DataSource = dt

Hope it works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top