I am trying to display image in crystal report using query. But There is no display and only blank field.
Dim conn As New OdbcConnection("dsn=localhost")
Dim cmd As OdbcCommand
Dim trans As New OdbcTransaction
Dim da As OdbcDataAdapter
Dim ds As New DataSet
Dim query = "SELECT @img as imgblob;"
cmd = New OdbcCommand(query,conn,trans)
Dim params = cmd.Parameters.Add("@img",OdbcType.Binary)
If File.Exists(Application.StartupPath & "\sample.png") Then
Dim img As Image = Image.FromFile(Application.StartupPath & "\sample.png")
Dim ms As New MemoryStream
img.Save(ms, ImageFormat.Png)
Dim binaryimg As Byte() = ms.GetBuffer()
params.Value = binaryimg
End If
da = New OdbcDataAdapter(cmd)
da.Fill(ds,"rpt_header")
I make sure that:
- file exists and returned true
- img is not null
- params has value
- ms.GetBuffer() has value
I tried so far:
- cast/convert @img in query
- changed parameter in query to '?'
- changed ImageFormat to Jpg, Png, Gif, etc.
- changed query to normal text and displayed expected output