Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert images into database ?

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
hi here is a comment

"insert the images into the database"

how do we insert images into database ?

i know how to create table,and type in data in those table columns.

but statement says to insert images into DB. is it possible to insert image into DB?

or does it mean to refer some folder where those images are stored and DB columns contains images id's ?

It is not clear
 
best to just hold the path to the images within the DB and hold the images elsewhere - it is possible to load the images into a table but Ive never done it that way.

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
>best to just hold the path to the images within the DB and hold the images elsewhere - it is possible to load the images into a table but Ive never done it that way.


hi thanks for the answer. i am familiar with the solution you said.

but in fact it seems to me that the whole image can be stored in the table so that servlet would read the binary image stream.

And not only image,but also i have read some articles where it is said .pdf files can also be stored in the DB.

could u plz tell how to save .pdf files or images inside DB ?

my server is MS-SQL server 7.0 .

i need to know the steps.

Thank you
 
in order to store images into database, it is called

"Store the byte contents of the images in a database column"

would you plz tell what are those steps in MS-SQL server 7 ? How to do it ?

thank you
 
Er, I just looked up image in T-SQL help, and there's a type called image that allows you to store images. I've never tried it, but it looks pretty easy.

HTH

Bob
 
I copied this from the knowledge base

How To Access and Modify SQL Server BLOB Data by Using the ADO Stream Object
Article ID : 258038
Last Review : July 15, 2004
Revision : 1.0
This article was previously published under Q258038
On this page
SUMMARY
MORE INFORMATION
REFERENCES

SUMMARY
The Stream object introduced in ActiveX Data Objects (ADO) 2.5 can be used to greatly simplify the code that needs to be written to access and modify Binary Large Object (BLOB) data in a SQL Server Database. The previous versions of ADO [ 2.0, 2.1, and 2.1 SP2 ] required careful usage of the GetChunk and AppendChunk methods of the Field Object to read and write BLOB data in fixed-size chunks from and to a BLOB column. An alternative to this method now exists with the advent of ADO 2.5. This article includes code samples that demonstrate how the Stream object can be used to program the following common tasks: • Save the data stored in a SQL Server Image column to a file on the hard disk.
• Move the contents of a .gif file to an Image column in a SQL Server table.

MORE INFORMATION
The following code samples are based on the data stored in the pub_info table in the SQL Server 7.0 pubs sample database. You need to modify the ADO connection string to point to your SQL Server installation.
Example 1 : Saving the Data in a SQL Server Image Column to a File on the Hard Disk
The code in this example opens a recordset on the pub_info table in the pubs database and saves the binary image data stored in the logo column of the first record to a file on the hard disk, as follows: 1. Open a new Standard EXE Visual Basic project.
2. On the Project menu, click to select References, and then set a reference to the Microsoft ActiveX Data Objects 2.5 Object Library.
3. Place a CommandButton control on Form1.
4. Make the following declarations in the form's General declarations section: Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream


5. Cut and paste the following code into the Click event of the CommandButton that you added to the form: Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=<name of your SQL Server>;
Initial Catalog=pubs;User Id=<Your Userid>;Password=<Your Password>"

Set rs = New ADODB.Recordset
rs.Open "Select * from pub_info", cn, adOpenKeyset, adLockOptimistic

Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("logo").Value
mstream.SaveToFile "c:\publogo.gif", adSaveCreateOverWrite

rs.Close
cn.Close


6. Save and run the Visual Basic project.
7. Click the CommandButton to save the binary data in the logo column of the first record to the file c:\publogo.gid. Look for this file in Windows Explorer and open it to view the saved image.

The code in this example declares an ADODB Stream object and sets its Type property to adTypeBinary to reflect that this object will be used to work with Binary data. Following this, the binary data stored in the logo column of the first record in the pub_info table is written out to the Stream object by calling its Write method. The Stream object now contains the binary data that is saved to the file by calling its SaveToFile method and passing in the path to the file. The adSaveCreateOverWrite constant passed in as the second parameter causes the SaveToFile method to overwrite the specified file if it already exists.

Example 2 : Transfer the Image Stored in a .gif File to an Image Column in a SQL Server Table
The code in this example saves an image stored in a .gif file to the logo column in the first record of the pub_info table by overwriting its current contents, as follows: 1. Open a new Standard EXE Visual Basic project.
2. On the Project menu, click to select References, and then set a reference to the Microsoft ActiveX Data Objects 2.5 Object Library.
3. Place a CommandButton on Form1.
4. Make the following declarations in the form's General declarations section:Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream


5. Cut and paste the following code in the Click event of the CommandButton that you added to the form:Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=<name of your SQL Server>;
Initial Catalog=pubs;User Id=<Your Userid>;Password=<Your Password>"

Set rs = New ADODB.Recordset
rs.Open "Select * from pub_info", cn, adOpenKeyset, adLockOptimistic

Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "<path to .gif file>"
rs.Fields("logo").Value = mstream.Read
rs.Update

rs.Close
cn.Close


6. Save and run the Visual Basic project.
7. Click on the CommandButton to run the code to stream the contents of the .gif file to the ADO Stream object, and save the data in the Stream to the logo column in the first record of the recordset.
8. Verify that the image in the logo column has been modified by using the code in Example 1.

REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
308042 How To Read and Write BLOB Data by Using ADO.NET with Visual Basic .NET
 
Check my response above om ADO STREAM.

I use the ADO STREAM function to store .bmp images into a sql table. These are photos of flaws in a product.

I use WINZIP COMMANDs to zip the images before storing and restoring after retrieval. The zipped images take about 25% of the space of the .bmp.

There are thousands of these images which cluttered up the Windows directories and storing in the sql table eliminated them.

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top