Store and Display Images from MS Access Database Using C#

by top54u.com 29 Feb, 2008
Spotlight.....

There is only the difference of coding syntax to stream the binary data of image content type to upload it into MS Access Database using C#/VB in ASP.Net 2.0

 

Namespaces required:

 

using System.Data.OleDb;

OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0

 

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:

 

int imageSize;

string imageType;

Stream imageStream;

// Gets the Size of the Image

imageSize = fileImgUpload.PostedFile.ContentLength;

 

// Gets the Image Type

imageType = fileImgUpload.PostedFile.ContentType;

 

// Reads the Image stream

imageStream = fileImgUpload.PostedFile.InputStream;

 

byte[] imageContent = new byte[imageSize]; int intStatus;

intStatus = imageStream.Read(imageContent, 0, imageSize);

 

Connection string to connect the ASP.Net 2.0 web application with MS Access Database:

 

// Access Database oledb connection string

// Using Provider Microsoft.Jet.OLEDB.4.0

String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");

 

Download the free source code in ASP.Net 2.0 using C#:

AccessImagesCSharp.zip (124.18 kb)

AccessImagesCSharp.rar (71.59 kb)

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Comments

3/18/2008 3:14:34 PM

Pratik

This site satisfy my requirment with good codding.
If u have this king of codding please send me on my Email ID.
Thanks..........

Pratik in

3/19/2008 8:29:45 PM

premkumar

hi, it is usefull when developing projects

premkumar in

4/19/2008 9:07:51 PM

Archit Shrivastav

really useful post

Archit Shrivastav in

4/20/2008 4:32:08 PM

laxman

how to store imagesize in database

laxman in

4/20/2008 8:10:18 PM

Top54u

Hi Laxman
If you want to save imagesize in bytes then first of all create a new field img_size as number in MS Access database to store the imagesize.
Then modify the insert query by adding the new img_size field along with its parameter (@img_size) to set its value.
You can download the sample code provided with this article and apply the changes as above.

Top54u us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:41:02 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....