Click to See Complete Forum and Search --> : Inserting images into database
srinivasreddyp
August 20th, 2001, 02:43 AM
i have a tiff format image which was saved from a kodak image edit control and i want to insert in a field in sqlserver database. can any one of you please find a solution for me
and please also give solution how to retrieve it to the kodak image edit control
thanks in advance
Iouri
August 20th, 2001, 07:00 AM
'Try this
Const MAX_PATH = 255
private Const CHUNK_SIZE = 1000
private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (byval nBufferLength as Long, _byval lpBuffer as string) as Long
public Function SavePictureToDB(PictControl as Object, _
RS as Object, FieldName as string) as Boolean
'PURPOSE: SAVES PICTURE IN IMAGEBOX, PICTUREBOX, OR SIMILAR
'CONTROL to RECORDSET RS IN FIELD NAME FIELDNAME
'FIELD TYPE MUST BE binary (OLE OBJECT IN ACCESS)
'SAMPLE USAGE
'Dim sConn as string
'Dim oConn as new ADODB.Connection
'Dim oRs as new ADODB.Recordset''
'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
'oConn.Open sConn
'oRs.Open "SELECT * FROM MYTABLE", oConn, adOpenKeyset, _
adLockOptimistic
'oRs.AddNew
'SavePictureToDB Picture1, oRs, "MYFIELD"
'oRs.Update
'oRs.Close
Iouri Boutchkine
iouri@hotsheet.com
bill brave
December 19th, 2001, 09:40 PM
Please show me where is SavePictureToDB ?
Iouri
December 20th, 2001, 08:11 AM
Sorry the code got truncated on its way. Here is another procedure to save pic
in db
The Appendchunk()method can be used to achievd this also, but the usage of streams is a cleaner method
of coding.
Public Function SavePictureToDB(RS As ADODB.Recordset, _
sFileName As String)
On Error GoTo procNoPicture
Dim oPict As StdPicture
Set oPict = LoadPicture(sFileName)
'Exit Function if this is NOT a picture file
If oPict Is Nothing Then
MsgBox "Invalid Picture File!", vbOKOnly, "Oops!"
SavePictureToDB = False
GoTo procExitSub
End If
RS.AddNew
Set strStream = New ADODB.Stream
strStream.Type = adTypeBinary
strStream.Open
strStream.LoadFromFile sFileName
RS.Fields("***YourImageField***").Value = strStream.Read
Image1.Picture = LoadPicture(sFileName)
SavePictureToDB = True
procExitSub:
Exit Function
procNoPicture:
SavePictureToDB = False
GoTo procExitSub
End Function
Iouri Boutchkine
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.