How to save cell value(image) of a vertical grid control (devexpress) to sql database?

393 views Asked by At

I have a vgridcontrol of devexpress that contain a row for save user profile picture. How do I save images to the database?

When this code runs:

Image image = vgridcontrol.getcellvalue(row_photo, 0) as Image;

Image is null. Any ideas?

1

There are 1 answers

0
nempoBu4 On

Images are stored in a byte arrays, so you can simply save your byte array to SQL without converting to Image.

If you want to get the Image from byte array then you can get it from MemoryStream which is filled by your byte array:

var byteImage = (byte[])vGridControl1.GetCellValue(row_photo, 0);

if (byteImage == null)
    return;

using (var memoryStream = new MemoryStream(byteImage))
{
    var image = Image.FromStream(memoryStream);

    //Do whatever you want with your image.
}