Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Storing/retrieving images from UL database

22 views
Skip to first unread message

Scott Trafford

unread,
Jan 27, 2010, 4:47:43 PM1/27/10
to
Hi

Looking for some samples/info on how to store and retrieve images from
an UL database. Using v11 and programming using VB.NET.

There is an example listed in the sybase website on the codexchange (The
ULImage Sample Application) but its a dead link.

Basically, I have a table that has an image loaded on the server (using
xp_read_file) and I need a way to get that image out of the table on the
UL end. xp_write_file does not appear to work on UL.

Regards,
Scott

Chris Keating (Sybase iAnywhere)

unread,
Jan 28, 2010, 4:00:20 PM1/28/10
to
here is a basic implementation (note that lines may be wrapped):

Try
Dim ConnString As String = "dbf=images.udb"
conn = New ULConnection(ConnString)
conn.Open()

Dim bytes() As Byte

' get the image from disk
Dim input As New FileStream("source.jpg", FileMode.Open)
Dim reader As New BinaryReader(input)
bytes = reader.ReadBytes(CInt(input.Length))

' add image to database
Dim cmd As ULCommand = conn.CreateCommand()
cmd.Commandtext = "INSERT INTO t(c_image) VALUES (?)"
cmd.Parameters.Add("", bytes)
cmd.ExecuteNonQuery()
cmd.Dispose()

' retrieve the image from database
cmd = conn.CreateCommand()
cmd.CommandText = "SELECT c_image FROM t"
Dim dr As ULDataReader = cmd.ExecuteReader()
dr.MoveFirst()
bytes = dr.GetBytes(0)

' write image to a new file on disk
Dim output As New FileStream("image.jpg", FileMode.Create,
FileAccess.Write)
Dim writer As New BinaryWriter(output)
writer.Write(bytes)
writer.Flush()
writer.Close()

conn.Close()

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

0 new messages