user1600279
user1600279

Reputation:

passing parameter to report viewer

I want to pass a parameter to my report view. I have a drop down list with values from database and a button for displaying the report after selecting an item from the drop down list.

here is the code I wrote for adding the parameter

protected void Button1_Click(object sender, EventArgs e)
{
    RenderReport();
}

protected void RenderReport()
{
    try
    {
        ServerReport serverReport = ReportViewer1.ServerReport;
        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        try
        {
            serverReport.ReportServerUrl = new Uri("http://hedinaily-pc/Reports_HEDI");
        }
        catch (Exception ex)
        {
            Logger.Error(ex.Message, "");
        }
        serverReport.ReportPath = "~/Diagrammes/PresenceTotale.rdlc";
        ReportParameter employe = new ReportParameter();
        employe.Name = "Employe";
        employe.Values.Add(DropDownList1.SelectedValue);
        ReportViewer1.ServerReport.SetParameters( new ReportParameter[] { employe });
        ReportViewer1.Visible = true;               
    }

    catch (Exception ex)
    {
        Logger.Error(ex.Message, "");

    }

}

Here is the data set of my report

enter image description here

When I check my log file I find this error :

The attempt to connect to the report server failed.  Check your connection information and that the report server is a compatible version.

Can anyone tell me where doe's this error come from. I spent hours searching on google I found this LINK but I couldn't resolve it.

Upvotes: 4

Views: 24708

Answers (4)

Mayank Pathak
Mayank Pathak

Reputation: 3681

Try it like this...

ReportViewer1.ServerReport.ReportPath = "FooReport.rdlc";
ReportParameter[] reportParameter = new ReportParameter[2];
reportParameter[0] = new ReportParameter("fooFromDate", dateFrom.ToShortDateString());
reportParameter[1] = new ReportParameter("fooDateTo", dateTo.ToShortDateString());
ReportViewer1.ServerReport.SetParameters(reportParameter);
ReportViewer1.ServerReport.Refresh();

Also .Refresh() method must be called so that...report is displayed..

Upvotes: 4

ks.
ks.

Reputation: 1

For the "The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version." error try:

serverReport.ReportPath = "/Diagrammes/PresenceTotale";

instead of:

serverReport.ReportPath = "~/Diagrammes/PresenceTotale.rdlc";

Upvotes: 0

Girish Barje
Girish Barje

Reputation: 1

One way of doing the same is by using the Report Parameters dialog box to define parameters for a report that is processed in local mode. You can define parameters to support conditional formatting or to use in expressions or code. You cannot use the Report Parameters dialog box to map report parameters to query parameters or use them in data source filters.

So you can pass the parameters to the SP as we can do it in normal operation, by usign sqlParameters. Then execute the SP bind it to report viewer datasource.

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 29000

You can test with this code

    ReportParameter[] yourParams = new ReportParameter[1];
    yourParams [0] = new ReportParameter("Employe", DropDownList1.SelectedValue);//Adjust value

    this.ReportViewer1.ServerReport.SetParameters(yourParams  );

Upvotes: 0

Related Questions