将图像转换为ODBC参数

发布于 2025-02-05 19:46:20 字数 981 浏览 2 评论 0原文

我正在尝试使用查询在Crystal Report中显示图像。但是没有显示屏,只有空白字段。

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

我确保存在:

  • 文件存在并返回的true
  • img不是null
  • 参数的value
  • ms.getBuffer()

在到目前为止尝试过的值:

  • cast/convert @img在查询中cast/convert @img
  • 在查询中更改了参数为'?
  • 将图像format更改为JPG,PNG,GIF等。
  • 将查询更改为普通文本,并显示了预期的输出

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文