简体   繁体   中英

How can i retrieve the image stored in binary format from database

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM