Search This Blog

Wednesday, 1 August 2012

Store and Display Images from MS Access Database Using C#


amespaces required

  1. using System.Data.OleDb;  
OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0
  1. using System.IO;  
IO is used to create the memory stream variable that can store the binary format of the image content.

C# Code to Upload Image to MS Access Database

  1. int imageSize;   
  2. string imageType;   
  3. Stream imageStream;  
  4.   
  5. // Gets the Size of the Image  
  6. imageSize = fileImgUpload.PostedFile.ContentLength;  
  7.   
  8. // Gets the Image Type  
  9. imageType = fileImgUpload.PostedFile.ContentType;  
  10.   
  11. // Reads the Image stream  
  12. imageStream = fileImgUpload.PostedFile.InputStream;  
  13.   
  14. byte[] imageContent = newbyte[imageSize]; int intStatus;   
  15.   
  16. intStatus = imageStream.Read(imageContent, 0, imageSize);   
Connection string to connect the ASP.Net 2.0 web application with MS Access Database:
  1. // Access Database oledb connection string   
  2. // Using Provider Microsoft.Jet.OLEDB.4.0   
  3. String connStr = "Provider=Microsoft.Jet.OL

No comments:

Post a Comment

Popular Posts