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
- ID AutoNumber (Primary Key)
- ImageName Text
- ImageValue OLE Object
Now create a WebApplication and add following controls on the Web Form
- Upload Control
- Button for uploading image and saving into database
- DropdownList for listing all the images in Dabase Table
- Button for saving the image into a folder
- Image to show the image save on the disk
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
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
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.
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
thanks a lot :-)
ReplyDelete