Here I've given a very simple code snippet with you can display image from database.
private void DisplayPictureFromDB()
{
private void DisplayPictureFromDB()
{
SqlConnection cnMyPro = new SqlConnection();
string qryMyPro = "SELECT Description FROM ProductInfo";
if (cnMyPro.State != ConnectionState.Open)
cnMyPro.Open();
SqlCommand cmdMyPro = new SqlCommand(qryMyPro, cnMyPro);
SqlDataReader sdrMyPro =cmdMyPro.ExecuteReader();
sdrMyPro.Read();
if (sdrMyPro.HasRows)
{
byte[] MyImage = (byte[])(sdrMyPro[2]);
if (MyImage == null)
picDescription.Image = null;
else
{
MemoryStream msMyPro = new MemoryStream(MyImage);
picDescription.Image =Image.FromStream(msMyPro);
}
}
}
1 comment:
Well Done. But This process will increase the weight of your DB to future maintenance. Better to use file repository as like How a mail server deal its attachments with the mail.
Post a Comment