Storing Images in Sql Server & V.B 
Author Message
 Storing Images in Sql Server & V.B

Robert

I'm currently developing a Staff database using VB6 & SQL 7, one of the
requirements is that we hold pictures.  I've loaded (I think) a record with
a file using your embedding code, but would like to display it in an image
control when retrieved, rather than save it back to disk. My cmdFind code
(test database) has

Private Sub cmdFind_Click()

    Set rsPic = New ADODB.Recordset
    rsPic.Open "Select Picture from tblPic", cn, adOpenForwardOnly,
adLockReadOnly
    imgPic.Picture = rsPic!Picture
    rsPic.Close

End Sub

However when I run it, I'm getting a 'Type Mismatch' error on the  line
imgPic.Picture = rsPic!Picture  Any pointers on this.

Thanks

John


Quote:
> The following code works fine when using Access 97 or 2000 and on small
> files in SQL 6.5 and SQL 7.
> On large files in SQL6.5 and SQL7 it fails. Still trying to figure out how
> to do same with larger files.
> This code takes pictures stored in files. Haven't got any code to take
> images stored in picture controls, however since they usually originate in
> files you can probably use this.
> Hope it helps.

> Embedding :
> Dim Fnum as integer
> Dim Fname as string
> Dim Fcontent() as Byte
> Dim MyRs as recordset
>  Fnum = FreeFile
>         Fname = FileName
>         Fname "C:\Myfile.jpg"
>  Open Fname For Binary As #Fnum
>             ReDim Fcontent(LOF(Fnum)) As Byte
>             Get #Fnum, , Fcontent
>         Close #Fnum
>         MyRs.addnew
>   MyRs("imagefield").AppendChunk Fcontent
>         MyRs.Update

> Extracting:
> Dim Fnum as integer
> Dim Fname as string
> Dim Fcontent() as Byte
> Dim MyRs as recordset
>  'code to open the recordset and find the required record containing the
> image
>  'after you have found the record
>  ReDim Fcontent(MyRs("imagefield").FieldSize)
>         Fcontent = MyRs("imagefield").GetChunk(0,
> MyRs("imagefield").FieldSize)
>         'you can now put the file content to a disk file to view later
>         Fnum = FreeFile
>         Open Fname For Binary As #Fnum
>         Put #Fnum, , Fcontent
>         Close #Fnum

> --
> Robert Dufour, MCP, MCT
> President SGI IMS Inc.
> www.sgiims.com

> > hi Friends,

> >  Regarding Storing Image in Sql Server & Visual Basic.

> >  I am using Visual Basic Application as Front End & Sql Server as Back
> > End.
> > I want to Store a Picture/Image in a Table. For that i am using the
> > field type
> > as Image. In Visual Basic form I have a Picture Control & Image Control.

> >      I have a image/Picture in that control. I want to store it in the
> > Table
> > & manipulate Image/Picture. For retriving from table i am using
> > Recordset.

> >      Please give me an example to do this.

> > Regards,
> > Prakash



Fri, 15 Nov 2002 03:00:00 GMT  
 Storing Images in Sql Server & V.B

Quote:
> but would like to display it in an image
> control when retrieved, rather than save it back to disk

Check this tip:

http://www.domaindlx.com/e_morcillo/scripts/cod/showtip.asp?code=pcarr

--
Eduardo A. Morcillo
http://www.domaindlx.com/e_morcillo



Fri, 15 Nov 2002 03:00:00 GMT  
 Storing Images in Sql Server & V.B
You have to say to the system  with witch database it will work with
Try
dim dbs as database
set dbs=currentdb()

set rst=dbs.openrecordset("..........",dbopensnapshot)



Quote:

> > but would like to display it in an image
> > control when retrieved, rather than save it back to disk

> Check this tip:

> http://www.domaindlx.com/e_morcillo/scripts/cod/showtip.asp?code=pcarr

> --
> Eduardo A. Morcillo
> http://www.domaindlx.com/e_morcillo



Sat, 16 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Storing Images in Sql Server & V.B

2. Storing Images in Sql Server & V.B

3. Storing Images in Sql Server & V.B

4. Storing Images in Sql Server & V.B

5. Storing Images in Sql Server & V.B

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

7. Problem to store image in SQL server 6.0 with VB 4

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

9. VB 5.0 & Stored Procedure (SQL Server 6.5)

10. STORING /LOADING IMAGES FROM ACCESS DATABASE / SQL SERVER

11. storing bit-map image (bmp or jpg) on SQL Server

12. Storing and Retrieving Images in SQL Server

 

 
Powered by phpBB® Forum Software