Monday, April 2, 2012

How To Retrieve an image SQL Server Data type into Picture Box Using C#

Note: Before reading this blog,  you need to know (How To Store an Image to image SQL Server Data type Using C#)

Images are stored in SQL Server database as series of bytes; to retrieve an image into Picture Box follow these steps

1- Crete a stored procedure that do select command on an image
2- In C# code get the array byte retrieved from the database and convert it to Image 
        
        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }


3- Set the converted image to the picture box 


For more details watch this video







and download the source code for experiment purposes

1 comment: