views:

390

answers:

2

Hi, How can i show diffrent pictures based on a value in the databse in my rdlc report? for example, costumer - K1, wants picture1, while costumer K2, wants picture2. But i want this value insted 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 paramter from my datbase showing the value in rdlc. If this is not possible any other quick solutions how to show diffrent pictures when the value is diffrent?

A: 

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.

sindre j
A: 

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);
        }
    }
    ....
cdonner