Reputation: 73
How can I show different pictures based on a value in the database in my rdlc report? for example, costumer - K1, wants picture1, while costumer K2, wants picture2. But I want this value instead to show a picture.
My costumers is insterted into a table. And then sent to the rdlc. This is working so i can fetch the diffrent costumer names, but I want the value 1 to show picture 1 while the value 2 shows the picture 2. I have a parameter from my database showing the value in rdlc. If this is not possible any other quick solutions how to show different pictures when the value is different?
Upvotes: 1
Views: 1774
Reputation: 37698
Or, if you use Linq to SQL, you can add a property to the partial class of the type in your result set. I use stored procedures for my reports and use this code add a barcode image for an order number:
[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);
}
}
....
Upvotes: 0
Reputation: 4444
You can add a byte array column to the dataset and initialize that column based on the criteria you want. I use this for displaying dynamic graphics based on data in reports.
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();
Now, you can set the pictureColum (which is defined as a byte array) as source for your picture object.
Upvotes: 2