Solved

Filter a report by date range in Reportviewer

Posted on 2011-09-12
5
1,054 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 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