Read Bitmap from database : Image Load Save : ADO.Net C# Examples


C# Examples » ADO.Net » Image Load Save »

 

Read Bitmap from database









    
using  System;
using  System.Data;
using  System.Data.SqlClient;
using  System.Drawing;
using  System.IO;

public  class  MainClass
{
      public  static  void  Main()
      {
            SqlConnection    imageConnection  =  new  SqlConnection(@"data  source  =  .\sqlexpress;integrated  security  =  true;initial  catalog  =  tempdb;");

            SqlCommand  imageCommand  =  new  SqlCommand(@"select  imagefile,imagedata  from  imagetable  ",imageConnection);

            imageConnection.Open();
            SqlDataReader  imageReader  =  imageCommand.ExecuteReader();

            string  imageFilename  =  (string)  imageReader.GetValue(0);
            byte[]  imageBytes  =  (byte[])  imageReader.GetValue(1);

            MemoryStream  ms  =  new  MemoryStream(imageBytes);
            Bitmap  bmap  =  new  Bitmap(ms);

            imageReader.Close();
            imageConnection.Close();
      }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» Image Load Save