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
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