将图像转换为ODBC参数
我正在尝试使用查询在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论