BLOB image from postgres to VB2005

riverslucas
03-23-2006, 11:03 AM
Hi, I'm new at VB, and I'm trying to extract an image from a postgres database and set it on a picturebox control. I have read an article about how to do it using Access, and I've used the code of the article. But an error occurs when I execute the program, it says "Outofmemory"... and I don't know how to fix it... Please, if anybody knows how to fix that or another way to do it... just drop a line here!

The code is:

Dim cn As OdbcConnection
Dim cmd As Odbc.OdbcCommand
Dim res As Odbc.OdbcDataReader
Dim fs As FileStream
Dim bw As BinaryWriter
Dim bufferSize As Long = 3000000
Dim outbyte(3000000 - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Dim pub_id As String = ""
Dim savedimagename As String = "c:\temp.bmp"
Dim curimage As New Bitmap(256, 266)

consulta = "select * from imgprueba"
cn = New OdbcConnection("dsn=PostgreSQL ANSI;uid=postgres;pwd=;")
cn.Open()
cmd = New Odbc.OdbcCommand(consulta, cn)
res = cmd.ExecuteReader(CommandBehavior.SequentialAccess)
res.Read()
Try
fs = New FileStream(savedimagename, FileMode.OpenOrCreate, FileAccess.Write)
bw = New BinaryWriter(fs)
startIndex = 0
retval = res.GetBytes(2, 1, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
' Close the output file.
bw.Close()
fs.Close()
res.Close()
' Display image
curimage = Image.FromFile("c:\temp.bmp")

imgcontainer.Image = curimage
imgcontainer.Invalidate()

Catch ex As Exception
MsgBox(ex.Message & ex.Source)
End Try

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum