Saturday, November 25, 2006

how to save images in postgresql database

Set ImgXCtrl1.Picture = LoadPicture("c:\windows\wallpaperbrucelee14.jpg")

Set c = New ADODB.Connection
c.CursorLocation = adUseClient
c.Open "Driver={PostgreSQL ANSI};uid=postgres-su;pwd=whiteboard-su;Server=localhost;Database=test;ByteaAsLongVarBinary=1"





Dim jpg As New MycJpg ' core code comes from intel jpeg library

Set r = New ADODB.Recordset
r.CursorLocation = adUseClient
r.Open "SELECT i, imx FROM images where 1 = 0", c, adOpenStatic, adLockOptimistic


Dim b() As Byte
b = jpg.PicToJpba(ImgXCtrl1.Picture)


r.AddNew
r.Fields("i").Value = 3
r.Fields("imx").Value = b
r.Update

No comments: