当只有图像名称保存在数据库中时,如何在 RDLC 报告中显示图像?

How to display image in RDLC report from when only image name saved in database?

我只在数据库中存储图片名称,实际图片存储在项目目录中'SiteImages'。

现在我想在 RDLC 报告中显示图像,但没有显示。 代码:

public void Fill_AuditsReport()
{
    ReportViewer1.AsyncRendering = false;
    ReportViewer1.SizeToReportContent = true;
    ReportViewer1.ZoomMode = ZoomMode.FullPage;
    this.ReportViewer1.Reset();

    DataTable dt = new DataTable();
    PersonalInfo.ManagePersonalInfo MngPersonalInfo = new PersonalInfo.ManagePersonalInfo();

    dt = MngPersonalInfo.ReportSelectPersonalInfo();

    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/DataManagementReports/Report.rdlc");
    ReportDataSource rpds = new ReportDataSource("DataSetPersonalInfo", dt);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rpds);
    ReportViewer1.Visible = true;
}

数据库中的字段名称是PersonalInfoEmployeePicture

将以下代码添加到您的项目中:

ReportViewer1.LocalReport.EnableExternalImages = true;
string FilePath = @"file:\" + Application.StartupPath + "\" + "SiteImages\"; //Application.StartupPath is for WinForms, you should try AppDomain.CurrentDomain.BaseDirectory  for .net
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("ImgPath", FilePath);
ReportViewer1.LocalReport.SetParameters(param);

然后在报表设计器中,确保图像项在 External 上设置了图像源 属性 并且您有一个具有正确名称 (ImgPath) 的参数。然后简单地定义一个指向正确图像的表达式。 (这将取决于您在数据库中存储图像名称的方式,我们没有扩展名,我假设您添加了扩展名)

= Parameters!ImgPath.Value + Fields!PersonalInfoEmployeePicture.Value