Friday, April 10, 2009

Save Images in Access Database : ASP.NET

Using OLE Object we can save images in Access Database, in this example we will select a image and save that image in Access database using ASP.NET.

First we will start creating a table in access database.

Create a table ImageTable with following fields

  1. ID    AutoNumber (Primary Key)
  2. ImageName   Text
  3. ImageValue OLE Object

Now create a WebApplication and add following controls on the Web Form

  1. Upload Control
  2. Button for uploading image and saving into database
  3. DropdownList for listing all the images in Dabase Table
  4. Button for saving the image into a folder
  5. Image to show the image save on the disk

html

Initially we will fetch the image names which are already saved in the table and show in the drop down list,  for that use Page_Load method and insert following code

Page_Load

now double click on upload image button and add following code, in following code we are just reading the image into stream of bytes and we are storing into the database

UploadImage

To resave the image on to the disk we will use following code, once we save image from database to disk we will show that image in image1 control.

SaveImage

now we are ready with our code just build, run and test

hope this helps

Tags: Save images in Access Database, ASP.NET, Save images in Database

1 comment: