C#report使用reportViewer以编程方式传递参数

时间:2014-06-09 13:40:19

标签: c# reportviewer

我花了几天时间试图解决这个问题......

我所拥有的是需要传递给报表然后使用reportViewer显示的GUID列表。

我可以用guid组装逗号分隔列表没问题......但是我不确定如何将参数传递给报告。该报告的作曲家说,我需要做的就是传递逗号分隔的GUID列表

我没有创建报告,也没有直接访问其构图....(我是否需要直接访问它?)

    private void getreport_Click(object sender, EventArgs e)
{

        //May/20/14 (02:07PM) [AST] - Bootty ton for getting the new RDL report.
    outputBox.Clear();
    reportViewer.Show();

    reportViewer.ServerReport.ReportServerUrl = new Uri("http://prdukhscasq01/reportserver");
    //reportViewer.ServerReport.ReportServerCredentials.ImpersonationUser = WindowsIdentity.GetCurrent();
    //reportViewer.ServerReport.ReportPath = "/Charge Reconciliation/Combined Charge Report";
    reportViewer.ServerReport.ReportPath = "Scheduled Reports/HandOver/UK_HandOver_RoundingReport";



    //May/20/14 (04:14PM) [AST] - Must manually declare the reporting type because Obj+ contains its own report params
    // Dynamically creates a container for the paramerter to be passed to the report.

    int additional_params = 1;
    string patients_guids = "";

        // Counter for keeping track of where we are in the rows to inject the params
    int count = 0 + additional_params;

    Microsoft.Reporting.WinForms.ReportParameter[] yourParams
        = new Microsoft.Reporting.WinForms.ReportParameter[dataGridViewPatients.RowCount+additional_params];

        // additional peramiters can be added here.  you must add to the counter for each param in order for thet count to be correnct in the for each loop


        // Grabs current context to allow pulling of data from current session
    //CustomContextObj cc = CustomContextObj.GetInstance();

        //Param #1 logge in user guid


    //** need to create a DB connection using Current connection find this in the CV3ClientVisit table.


    foreach (Patient p in getSelectedPatients().Value)
    {
        patients_guids += p.VisitGUID + "'";
        MessageBox.Show(p.VisitGUID);
    }

 //  yourParams[0] = new Microsoft.Reporting.WinForms.ReportParameter("User_Guid",cc.UserGUID.ToString())
               // goes threw all of the names populated to the list
   /* foreach (DataGridViewRow row in dataGridViewPatients.Rows)
    {
           //keeps our current position in check


        yourParams[count] =
            new Microsoft.Reporting.WinForms.ReportParameter(row.Cells[0].Value.ToString(),row.Cells[1].Value.ToString());

        MessageBox.Show(row.Cells[0].Value.ToString()+ "," +row.Cells[1].Value.ToString());

        ++count;

    }*/



    // EX.. yourParams[0] = new Microsoft.Reporting.WinForms.ReportParameter("Employe", "data");//Adjust value




        // Completed Refresh
    reportViewer.RefreshReport();
}

我对这份RDL报道很新,并为我的无知道歉......任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

通过一些搜索和探索,我想出了答案。

您的参数必须与报告中的名称完全匹配。

GUIDstring是其中一个报告参数的名称。

   private void getreport_Click(object sender, EventArgs e)

    {



            //May/20/14 (02:07PM) [AST] - Bootty ton for getting the new RDL report.

        outputBox.Clear();

        reportViewer.Show();



        reportViewer.ServerReport.ReportServerUrl = new Uri("http://prdukhscasq01/reportserver");

        //reportViewer.ServerReport.ReportServerCredentials.ImpersonationUser = WindowsIdentity.GetCurrent();

        //reportViewer.ServerReport.ReportPath = "/Charge Reconciliation/Combined Charge Report";

        reportViewer.ServerReport.ReportPath = "/Scheduled Reports/HandOver/UK_HandOver_RoundingReport";

        //                                      Scheduled Reports/HandOver/UK_HandOver_RoundingReport





        //May/20/14 (04:14PM) [AST] - Must manually declare the reporting type because Obj+ contains its own report params



        string patients_guids = "";







        foreach (Patient p in getSelectedPatients().Value)

        {

            patients_guids += p.VisitGUID + ",";



        }





        // Assembles the parameter to pass guids.  Matching that of the report.

        Microsoft.Reporting.WinForms.ReportParameter patient_guids_param =

            new Microsoft.Reporting.WinForms.ReportParameter("GUIDstring", patients_guids);



        reportViewer.ServerReport.SetParameters(patient_guids_param);





            // Completed Refresh

        reportViewer.RefreshReport();

    }
相关问题