Creating a Report using ReportViewer in VisualStudio2010 with parameters passing! RRS feed

  • Question

  • User273232671 posted

    Hellow experts, this is the first time i work with report viewer, i have created my .rdlc file and already used the tool and everything went successfuly and the report got generated nicely, PUT, i used Select * from MyTable, so it showed me all the records in the table, and i dont want that, i want the user to chose 2 dates through 2 textboxes, and the report gets generated abon that condition, which is more like (Select * from MyTable where date => TextBox1.Text AND date =< TextBox2.Text).


    Can anyone help me with this please using VB.Net NOT C#, I've been searching the net for the longest time but not lcuk, i found one C# code but when i converted it using a converted and applied it in my Web Form it gave so many errors, and thanx in advance.

    Saturday, December 3, 2011 2:39 AM

All replies

  • User-96295490 posted


    You can accomplish this in two ways :

    1. Create Date controls outside the report viewer control in the form and on submit button click you can pass the values to the stored procedure of the Report.

    This has to be done in the code side like for example

    Private Sub SetReportParameters(ByVal viewer As ReportViewer)
        ''# use parameters to pass info to report
        Dim myStartDate As New ReportParameter("StartDate", Request.QueryString("startDt"))
        Dim myEndDate As New ReportParameter("EndDate", Request.QueryString("endDt"))
            ''# add parameters to the report
            viewer.LocalReport.SetParameters( _
                New ReportParameter() {myStartDate, myEndDate})
        Catch ex As Exception
            ErrorLabel.Text = DATABASE_ERROR_MSG
        End Try
    End Sub


    2. Other way to do this is very simple create a report in ssrs with parameters you will get default date control while creating the parameters. Pass the parameter to the report stored procedure. Then once you deploy this particular report in the report server link this report to the report viewer control in the web application. I guess this should get you an idea to kick start.

    MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
    MyReportViewer.ServerReport.ReportServerUrl = new Uri("http://Your Report Server"); // Report Server URL
    MyReportViewer.ServerReport.ReportPath = "/Test Report"; // Report Name
    MyReportViewer.ShowParameterPrompts = true;
    MyReportViewer.ShowPrintButton = true;

    I guess this should help you get started.


    P.Anish Shenoy

    Tuesday, December 13, 2011 9:51 AM