Save image in Sql Server and retrieve image from sqlserver to vb 
Author Message
 Save image in Sql Server and retrieve image from sqlserver to vb
Hi
How to save a image to sqlserver .
How to retrieve a image from sqlserver database.

How to do these in ACCESS.

regards




Sat, 06 Mar 2004 17:42:03 GMT  
 Save image in Sql Server and retrieve image from sqlserver to vb
Lookup getchunk and appendchunk.  There are plenty of examples...


Quote:
> Hi
> How to save a image to sqlserver .
> How to retrieve a image from sqlserver database.

> How to do these in ACCESS.

> regards




Sun, 07 Mar 2004 11:11:00 GMT  
 Save image in Sql Server and retrieve image from sqlserver to vb
Hi,

To store a picture in the Sql server database, you need to create a table
with an image field in SQL server first. Then, you can use the ADO Stream
object to save the bitmap file into this table. Here are some sample codes
for you reference:

Private Sub Command1_Click()

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim filename As String
Dim fd As ADODB.Field
Dim strobj As New ADODB.Stream

With cn
  .ConnectionString = "Provider=SQLOLEDB.1;User
ID=test;Password=test;Initial Catalog=test;Data Source=bizvb"
  .Open
End With

'table1 contains a field named photo,which is used to stored the picture,
'a identity int field named ID which is the primary key
rs.Open "select * from table5", cn, adOpenKeyset, adLockOptimistic
Set fd = rs.Fields("photo")

rs.AddNew
filename = "c:\dd.bmp"
strobj.Type = adTypeBinary
strobj.Open
strobj.LoadFromFile filename
fd.Value = strobj.Read

Set fd = Nothing
rs.Update

rs.Close
cn.Close

End Sub

Note: Using the ADO Stream object requires ADO2.5 or later.

Another method is to use the Appendchunk function, for more information
please see the following article in Microsoft Knowledge base:

HOWTO: Sample Functions Demonstrating GetChunk and AppendChunk
http://support.microsoft.com/support/kb/articles/q194/9/75.asp

The simplest method to display the picture stored in the database is to
bind a Picturebox control or an Image control with the photo field of the
recordset that generate from the table. You also can use the Stream object
or GetChunk method to save the picture to a temp file on the hard driver,
and then load this file into the PictureBox or Image control.

For Access database, you can store images in an OLE object field. Besides
the above methods, you also can use DAO and OLE control to retrieve the
images.

Best Regards,
-Chali



Sun, 07 Mar 2004 15:18:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Retrieving an Image from SQL Server Image column (binary)

2. How to retrieve a bitmap-image from a SQL Server image field using ADO

3. Store and retrieve image on SQL server 7.0 using VB 6.0

4. Retrieve Bitmap of preview image - Summary Info - Save Preview Image

5. saving images into sql-server from VB.NET

6. Saving images to SQL Server using VB.net

7. Storing and Retrieving Images in SQL Server

8. Storing and Retrieving Images in SQL Server 6.5

9. Storing and Retrieving Images from Sql Server

10. Store the image in picture box control into the image data type in SQL server

11. Binding an Image control to an Image field in SQL Server

12. Binding an Image control to an Image field in SQL Server

 

 
Powered by phpBB® Forum Software