Skip to content Skip to sidebar Skip to footer

Retrieve Images From Sql Server Database

i am storing images to the database. How to retrieve all the images from the database. Eg: select images from imagetable Problem: Data Logic: while (dr.Read())

Solution 1:

this is an example from Sql Server

        connection.Open();
        SqlCommandcommand1=newSqlCommand("select imgfile from myimages where imgname=@param", connection);
        SqlParametermyparam= command1.Parameters.Add("@param", SqlDbType.NVarChar, 30);
        myparam.Value = txtimgname.Text;
        byte[] img = (byte[])command1.ExecuteScalar();
        MemoryStreamstr=newMemoryStream();
        str.Write(img, 0, img.Length);
        Bitmapbit=newBitmap(str);
        connection.Close();

look here http://www.akadia.com/services/dotnet_read_write_blob.html

Solution 2:

For SQL Server 2008 onwards, FILESTREAM is almost certainly the way to go.

Please see: SQL Server 2005 - How do I convert image data type to character format

Solution 3:

You need to get the binary data from the DB, and then stream the binary data to the browser as image.

Solution 4:

You are setting the Url of the image to be the byte stream - you need to save the image to the hard drive and provide the location.

A much better way would be to set the image url to be a resource handler with parameters that could then retrieve the image from the database and return it as a stream to the browser.

Post a Comment for "Retrieve Images From Sql Server Database"