0

I am storing the image in a database and using c# as the front end.

I am storing the image by converting into binary format.

How can I retrieve the image stored in binary format from database?

msturdy
  • 10,479
  • 11
  • 41
  • 52
Sunil Mathari
  • 822
  • 2
  • 11
  • 21
  • possible duplicate of [MVC How to display a byte array image from model](http://stackoverflow.com/questions/17952514/mvc-how-to-display-a-byte-array-image-from-model) – dav_i Jun 09 '14 at 11:48

1 Answers1

1

Maybe this will help:

OdbcConnection con = new OdbcConnection(ConnectString);
con.Open();
OdbcCommand checkcommand = new OdbcCommand("SELECT contents FROM MyTable WHERE MyClause",  con);
OdbcDataReader checkreader = checkcommand.ExecuteReader();
byte[] array = null;
if (checkreader.Read())
    array = (byte[])checkreader.GetValue(0);
else
{
   //Error
   return false;
}

File.WriteAllBytes("C:\\MyImage.jpeg", array);
Ramunas
  • 1,015
  • 1
  • 12
  • 19