簡體   English   中英

C#報表以編程方式通過reportViewer傳遞參數

[英]C# report programatically passing parameters with reportViewer

我花了幾天的時間試圖解決這個問題...

我所擁有的是GUID列表,需要將其傳遞到報表,然后使用reportViewer進行顯示。

我可以用逗號組合逗號分隔的列表,這沒問題...但是我不確定如何將參數傳遞給報告。 該報告的撰寫者說,我需要做的只是傳遞以逗號分隔的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報告資料很陌生,對我的無知表示歉意...任何幫助將不勝感激。

經過一番搜索和整理,我得出了答案。

您的參數必須與報告中的名稱完全匹配。

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();

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM