Solved

Filter a report by date range in Reportviewer

Posted on 2011-09-12
5
877 Views
Last Modified: 2012-05-12
I want to produce a report filtered by date range using microsofts report viewer

I have tried the following code which doesn't work. It returns an error saying incorrect number of parameters for CONVERT function.  I have used the label control to view the string passed to the filter expression and it looks correct.  Can anyone advise how to filter reportviewer reports by date range.

 protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
       
        Label20.Text = "[Date_SIF_Entered] > CONVERT(DATETIME," + TextBox1.Text + ",103) and [DATE_SIF_ENTERED] < CONVERT(DATETIME," + TextBox2.Text + ",103) ";
        ObjectDataSource4.FilterExpression = "[Date_SIF_Entered] > CONVERT(DATETIME," + TextBox1.Text + ",103) and [DATE_SIF_ENTERED] < CONVERT(DATETIME," + TextBox2.Text + ",103)";
        SifEntryReportByDateRange.LocalReport.Refresh();
    }
0
Comment
Question by:DCMBS
  • 4
5 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 36528002
Remove quotes " around TextBox.Text in the convert function. It returns string already.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23020764.html may help you.
0
 
LVL 9

Author Comment

by:DCMBS
ID: 36529144
I have had a look at the link and I have come up with the following.

I have an objectdatassource with two parameters of type datetime, FromDate and ToDate.

The report produces a report showing all records when no values are  defined for the parameters.

I have two Textboxes to allow the dates to be entered Textbox1 and Textbox2

I have created the following event handler for the on Text_Changed event of Textbox2.  The labels are just to let me inspect what is happening

protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        ObjectDataSource4.FilterExpression = "Date_SIF_Entered >= ' #{0}# ' and Date_SIF_Entered < ' #{1}#' ";
        Label20.Text = ObjectDataSource4.FilterExpression.ToString();
        Label21.Text = TextBox1.Text;
        Label22.Text = TextBox2.Text;
       
        /*SifEntryReportByDateRange.LocalReport.Refresh();*/
       
        ObjectDataSource4.FilterParameters["FromDate"].DefaultValue = TextBox1.Text;
        ObjectDataSource4.FilterParameters["ToDate"].DefaultValue = TextBox2.Text;
        //ObjectDataSource4.Select(DataSourceSelectArguments.Empty);
        SifEntryReportByDateRange.LocalReport.Refresh();
    }

This does not succeed in filtering the report.  Any help in working out why would be appreciated.
0
 
LVL 9

Author Comment

by:DCMBS
ID: 36529211
Abort that the above code works.  It requires the date in mm/dd/yyyy format though, which is not good.  I really need to=he date to be entered in dd/MM/yyyy format.
0
 
LVL 9

Author Comment

by:DCMBS
ID: 36529377
I have come up with the following for now.  Any further suggestions are welcome.  The date is entered as dd/mm/yyyy and then rearranged to US format mm/dd/yyyy

ObjectDataSource4.FilterExpression = "Date_SIF_Entered >= ' #{0}# ' and Date_SIF_Entered < ' #{1}#' ";
               
        String[] TempFromDate = TextBox1.Text.Split('/');        String[] TempToDate = TextBox2.Text.Split('/');
        String USToDate = TempToDate[1] + '/' + TempToDate[0] + '/' + TempToDate[2];  
       
        ObjectDataSource4.FilterParameters["FromDate"].DefaultValue = USFromDate;

        String USFromDate = TempFromDate[1] + '/' + TempFromDate[0] + '/' + TempFromDate[2];
           
        ObjectDataSource4.FilterParameters["ToDate"].DefaultValue = USToDate;
       
        SifEntryReportByDateRange.LocalReport.Refresh();
0
 
LVL 9

Author Closing Comment

by:DCMBS
ID: 36529384
The link pointed me to the solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now