Solved

Filter a report by date range in Reportviewer

Posted on 2011-09-12
5
944 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp enable view state 1 28
Add a Condition in ASP Repeater 6 34
looking for an ASP.net report designer 4 11
using CK editor in iframes 5 18
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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