Read Bitmap from database : Image Load Save « ADO.Net « C# / CSharp Tutorial






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








32.56.Image Load Save
32.56.1.Load image to database
32.56.2.Read Bitmap from database
32.56.3.Display image
32.56.4.Writes binary data to a file
32.56.5.LoadImages.cs