0

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
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 09 '22 at 09:42
  • The following may be helpful: https://stackoverflow.com/a/69638011/10024425 - it uses OLEDB but it should be similar for ODBC. – Tu deschizi eu inchid Jun 09 '22 at 17:35
  • Is there something missing from your code maybe? Seems a little odd that you're loading the image from file, then setting it as param on a select query that fills a dataset. The process just seems off, why not simply have your report load the image from file, or save the image in the DB? – Hursey Jun 09 '22 at 20:38

0 Answers0