Question:
How can we store an image in the database and access it?Tell the Steps?
Bukhari
2006-12-06 03:04:07 UTC
How can we store an image in the database and access it?Tell the Steps?
Five answers:
jan
2006-12-06 03:08:29 UTC
Here you go

http://www.datanamic.com/support/storeimagesinthedatabase.html

///
Linux OS
2006-12-06 03:18:17 UTC
It is impossible to answer this question without knowing the database used, and the method of database access.



Taking the most common - MySQL and PHP - an overview of the process is:



MySQL:

Create your database

Create a table

Create a row of type BLOB or LONGBLOB



PHP:

Create your test page. Use an input form to collect the data, and a standard MySQL command to store the data, for example:



Example mysql command:

INSERT INTO picture_d

(image_d)

VALUES ('$data')



Example input html within your form:

2006-12-06 03:07:10 UTC
You can store _any_ binary data in a blob field - search the internet for more information on blob fields, they're quite a big subject.



Rawlyn.
alnakash
2006-12-06 03:40:15 UTC
u can store images in folder and create field in db that contain the path of image.
Dev
2006-12-06 03:14:48 UTC
Access provides several ways to store images. You can:



Embed images directly in an OLE Object field in a database table.

What's an OLE Object field?



Object Linking and Embedding (OLE) is the technology used to share files among the various Office programs. For example, when you insert an Excel spreadsheet into a Word document, or insert a Microsoft PowerPoint slide into a Microsoft Visio drawing, you're using OLE. You use an OLE Object field when you need to store images (or links to them), and files from other Office programs directly in your database.



This method is the easiest to implement because you use the screens and tools that Access provides. Also, the images become part of your database and they travel with it. You never need to to update the links to your image files.



However, embedding images can rapidly inflate the size of your database and cause it to run slowly. This is especially true if you store GIF and JPEG files, because OLE creates additional bitmap files that contain display information for each of your image files, and those additional files can be larger than your original images. In addition, this method only supports the Windows Bitmap (.bmp) and Device Independent Bitmap (.dib) graphic file formats. If you want to display other common types of image files, such as GIF and JPEG images, you have to install additional software.



Store images on a hard drive or network and link to them from a database table.

This method is similar to the first, but instead of embedding images in an OLE Object field, you link to them. This method is a middle ground. Links don't take up as much space as embedded images, and you can use the screens and tools that Access provides to implement a solution.



However, if you move your database or your image files, you have to update your links, and your links also break if your files become corrupt. In addition, this method supports the same limited number of file types as the first method (Windows Bitmap and Device Independent Bitmap), and it requires additional software to display more file types.



Use Visual Basic for Applications (VBA) code to display the images.

This method involves storing images on a hard drive or network, storing the image paths and file names in a database table, and using code to set the properties for the Access image control and display images. This method requires programming, but it uses a very small amount of space, and you can use or adapt existing sample code. If you have a large number of images, this is the recommended method.



However, keep in mind that if you move your database, you also have to move the images.

The following sections explain how to use each storage method, and provide links to sample code.



Embed or link to images in a database table

The process of embedding or linking to images in a table follows these broad steps:



If you haven't already, add an OLE Object field to an existing table, or create a new table and add an OLE Object field.

Insert your image files into the field. During that process, you choose whether you embed or link to the image.

The following sections explain how to perform those tasks.



Add an OLE Object field to an existing table



Open the table in Design view .

In the first blank row of the design tool, under Field Name, enter Image.

Click the next field (the field in the Data Type column), and select OLE Object from the list.

Save the table.

Close the table in Design view, open it in Datasheet view (double-click the table to reopen it), and go to "Add images to the OLE Object field (embedded or linked)," later in this section.

Create a new table containing an OLE Object field



On the Objects bar in the Database window, click Tables, and then double-click Create table in Design view. The table design tool appears.

In the first row of the design tool, under Field Name, enter ID.

Click the first field under Data Type and select AutoNumber from the list.

Right-click anywhere in the first row and click Primary Key. This sets the ID field as the primary key for the table.

In the next row, enter Image in the Field Name column, and select OLE Object from the list in the Data Type column.

Save the table. You can accept the name that Access gives the table, or use another name.

Close the table in Design view, and then open it in Datasheet view (double-click the table to reopen it).

Continue to the next set of steps, "Add images to the OLE Object field (embedded or linked)."

Add images to the OLE Object field (embedded or linked)



The steps in this section use the existing or new tables described in the previous sections, plus a set of image files installed by Microsoft Office 2003. Alternatively, you can use your own tables and image files.



Right-click the first field in the Image column of the table and click Insert Object.

Click Create from File, and then click Browse.

Browse to one or more Windows Bitmap (.bmp) or Device Independent Bitmap (.dib) images. You can find a set of BMP files, named Empid1.bmp through Empid9.bmp, at drive:\Program Files\Microsoft Office\OFFICE11\SAMPLES. Select the first image and click OK.

This assumes you accepted the default installation path during Setup.



To link to an image, click Link, and then click OK again to complete the process. To embed the image in the table, leave the Link check box blank and click OK. The words Bitmap Image appear in the first field of the Images column in the table.

Note If Package appears in the OLE Object field, you're trying to link or embed an unsupported graphics file, such as a GIF or a JPEG. If you need to display those types of files, you can reinstall Microsoft Photo Editor. For more information about reinstalling Photo Editor, see What to do when you see "Package" instead of "Bitmap Image" in your database tables.



Go to the other fields in the Image column and repeat steps 2 through 5 until you've added the desired images.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...