如何在我的 rdlc 报告中根据数据库中的值显示不同的图片?例如,costumer - K1,想要picture1,而costumer K2,想要picture2。但我希望这个值改为显示图片。
我的客户被安置在一张桌子上。然后发送到rdlc。这是有效的,所以我可以获取不同的客户名称,但我希望值 1 显示图片 1,而值 2 显示图片 2。我的数据库中有一个参数显示 rdlc 中的值。如果这是不可能的任何其他快速解决方案,当值不同时如何显示不同的图片?
您可以将字节数组列添加到数据集,并根据您想要的条件初始化该列。我用它来显示基于报告中数据的动态图形。
Bitmap img = new Bitmap(width, height); // bitmap to display
// paint in the bitmap here
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // save bitmap to a memory stream
dataRow["pictureColumn"] = ms.GetBuffer();
现在,您可以将 pictureColum(定义为字节数组)设置为图片对象的源。
或者,如果您使用 Linq to SQL,您可以将属性添加到结果集中该类型的部分类。我为我的报告使用存储过程,并使用此代码为订单号添加条形码图像:
[Table]
public partial class sp_rpt_wcfResult
{
public byte[] OrderNumLabel {
get {
return
BarcodeUtilities.ConvertImageToByteArray(
BarcodeUtilities.GetBarcodeImage(this.order_number.ToString()),
System.Drawing.Imaging.ImageFormat.Bmp);
}
}
....