-1

I am developing a windows form application and I need to save and retrieve an image from an sql database. Actually I am storing the image values in a byte array but while I am retrieving data, I am not able to display the image. I have given my code below:

DataTable dtgetfeedback = Feedback.BOFeedBackRating.GetFeedBackratingcount(setFBRTID);

if (dtgetfeedback.Rows.Count > 0)
{
    gv_feedbackrating.DataSource = dtgetfeedback;
}
else
{
    gvdtgetdetail.Rows.Clear();
    DataRow drToAdd = gvdtgetdetail.NewRow();
    gvdtgetdetail.Rows.Add(drToAdd);
    gvdtgetdetail.AcceptChanges();
    gv_feedbackrating.DataSource = gvdtgetdetail;
}

Image values are stored bytearray

Image values are stored bytearray

Filburt
  • 17,626
  • 12
  • 64
  • 115
Raj
  • 5
  • 7
  • 2
    Possible duplicate of [How can I convert System.Byte\[\] to Image? (C# window forms)](https://stackoverflow.com/questions/3440366/how-can-i-convert-system-byte-to-image-c-window-forms) – Sinatr Oct 26 '17 at 10:25
  • Not Duplicate question actually this is needed to show image on Gridview not a picturebox – Raj Oct 26 '17 at 10:28
  • you can have picturbox control on a gridview column – Rahul Oct 26 '17 at 10:30
  • Actually, I had set picture edit repository in my grid column – Raj Oct 26 '17 at 10:31

2 Answers2

1

To show images based on byte arrays, assign RepositoryItemPictureEdit to the necessary column by setting the GridColumn.ColumnEdit property. In addition, set the RepositoryItemPictureEdit.PictureStoreMode property to ByteArray.

Svetlana
  • 421
  • 3
  • 5
0

Refer this - Saving and loading binary images into a picture edit control

When you have stored images in byte array format then it should be byte array format during retrieval from the database. Then add Change the PictureEdit's PictureStoreMode property to ByteArray

PictureEdit1.Properties.PictureStoreMode = DevExpress.XtraEditors.Controls.PictureStoreMode.ByteArray;

Related to view of image in the cells, By default, the RepositoryItemPictureEdit.SizeMode is the PictureSizeMode.Clip enumeration value of Clip. You may set the PictureSizeMode.Squeeze value. You may also specify the picture alignment at RepositoryItemPictureEdit.PictureAlignment.

References:
Bind a byte array to a PictureEdit
byte array column to image display
How to load a picture into the repositoryitemPictureEdit
ImageEdit binding

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • @Raj: If you have followed that way then it must work.. How are you saving data in database?? if data is correct everything should go fine – Niranjan Singh Oct 30 '17 at 16:56
  • You are correct, I found my issue because when I was set image to gridview that byte image size was 924 something, but while I am saving to database byte image size was 24 something. I don't know why it was reducing – Raj Oct 31 '17 at 05:59
  • Are you using DXHelper methods to convert it to byte array or from byte array to image.. e.g. `DevExpress.XtraExport.ByteImageConverter.ToByteArray(im, System.Drawing.Imaging.ImageFormat.Jpeg)` – Niranjan Singh Oct 31 '17 at 11:39
  • Thank you for your support Niranjan. Just I need to know retrieve varbinary data from sql server. can u help me this thing. if you want tell tell me ill send my code – Raj Oct 31 '17 at 12:37
  • @just create an small sample and it would be much better to understand that it is really a issue with controls or something else.. – Niranjan Singh Oct 31 '17 at 13:06