【问题标题】:How to pass both parameter and datasource to rdlc report sametime如何将参数和数据源同时传递给 rdlc 报告
【发布时间】:2018-12-26 06:00:28
【问题描述】:
    private void Test_Load(object sender, EventArgs e)
    {
        try
        {

            string sql = "[companyid]   ,[companyname] ,[Shopid]   ,[shopname],[shopaddress],[shopphone],[fax], [footermsg],[footermsg_ar] FROM [shop] Where id  = '1' ";
            DataAccess.ExecuteSQL(sql);
            DataTable dt = DataAccess.GetDataTable(sql);
            ReportDataSource reportDSDetail = new ReportDataSource("DataSet1", dt);

            string sqli = "SELECT [logo] FROM [logo] Where id= '1' ";
            DataAccess.ExecuteSQL(sql);
            DataTable dts = DataAccess.GetDataTable(sql);
            string path = Application.StartupPath + @"\LOGO\";
            string imagePath = path + dts.Rows[0].ItemArray[0].ToString();
            ReportParameter pImageUrl = new ReportParameter("pName", "file://" + imagePath, true);
            this.reportViewer1.LocalReport.ReportPath =path+@"Rep.rdlc";
            this.reportViewer1.LocalReport.EnableExternalImages = true;
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { pImageUrl });
            this.reportViewer1.LocalReport.DataSources.Add(reportDSDetail);
            this.reportViewer1.RefreshReport();

        }
        catch (Exception ex)
        {
            MessageBox.Show("Exception=" + ex);
        }
    }

在 RDLC 报告中,我创建了一个名为 pName 的参数,并与图像连接并配置了一个外部。 我需要在报表中获取参数和数据源,我尝试了很多方法但都失败了。 请帮我解决这个问题,以获取 RDLC 报告中的参数和数据源

【问题讨论】:

    标签: c# asp.net report rdlc


    【解决方案1】:

    首先你需要去Report Data并像这样添加Parameters

    在添加参数 Right Click on textbox 之后,您要在其中显示 parameters--> Click Expression 并添加 Expression 像这样

    其中Showdt 是parameter 名称

    像这样从code behind 传递data source 和parameters 一起

    ReportDataSource rds = new ReportDataSource();//pass Your Datasource
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportParameter p1 = new ReportParameter("Showdt", "Date : " + DateTime.Now.ToShortDateString());
    //you can add multiple parameter like this
    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[]{p1}); 
     ReportViewer1.LocalReport.DataSources.Add(rds);
     ReportViewer1.LocalReport.Refresh(); 
    

    you can check this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多