I have a listview that pulls data from a MySQL and I can now finally sort queries by date range (thanks Unhnd Exception!!). Also in that query, I have it sorted by ID number.

This brings me to another question. The ReportViewer pulls up a really nice report for my users with this data. Now I can sort it by:

1: User ID Number (officer_id in MySQL) OR
2: Date range (startdate and enddate in MySQL)

So here's what I have so far.

I can use the following filters to sort my query by officer ID number in the ReportViewer-

'Filtering the DataGrid to display only the rows of the selected Officer ID given in the main form textbox.text
        TrainingBindingSource.Filter = "Officer_ID LIKE '%" & frmMain.lblID.Text & "%'"

Then, I figured out how to sort and display my query in the report viewer with this statement-

TrainingBindingSource.Filter = String.Format _
        ("startdate >= #{0:MMM/dd/yyyy}# And enddate <= #{1:MMM/dd/yyyy}#", frmMain.dtpTrainingStart.Text, frmMain.dtpTrainingEnd.Text)

The first code works well sorting by the oficers ID number, and the second one works well sorting by date.

But how do I combine the both of them? As it is, they don't work as separate filters. I guess they need to be all meshed together?

Recommended Answers

All 2 Replies

Try this:

TrainingBindingSource.Filter = String.Format _
        ("startdate >= #{0:MMM/dd/yyyy}# And enddate <= #{1:MMM/dd/yyyy}#", frmMain.dtpTrainingStart.Text, frmMain.dtpTrainingEnd.Text)
TrainingBindingSource.Filter = TrainingBindingSource.Filter &" and Officer_ID LIKE '%" & frmMain.lblID.Text & "%'"

PS: If that doesn't work debug.print trainingbindingsource.filter will help you verify the criteria being passed.

Yup, that worked. I see how you did that- thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.