水晶报表动态显示图片
发布网友
发布时间:2022-05-01 19:45
我来回答
共2个回答
热心网友
时间:2022-05-04 01:35
我VS2005+水晶报表9+sql2005可以显示图(也是尝试了很久>1个月)
做法是:用推模式,先把数据查询放在dataset(下面的DS)中,数据源中添加一个image字段,我是把PhotoPath转成image字段CAST(M.PhotoPath AS image) AS image,然后再把图片读取到image字段,就可以显示到水晶报表中了,你是用什么方法做的?
For index As Integer = 0 To DS.Tables(0).Rows.Count - 1
Dim aa As String = DS.Tables(0).Rows(index).Item("MoldNo").ToString
If Not String.IsNullOrEmpty(DS.Tables(0).Rows(index).Item("PhotoPath").ToString) Then
LoadImage(DS.Tables(0).Rows(index), "Image", DS.Tables(0).Rows(index).Item("PhotoPath").ToString)
Else
LoadImage(DS.Tables(0).Rows(index), "Image", "~/UploadFile/NotAvailable.jpg")
End If
Next
report.SetDataSource(DS.Tables(0))
DS.Dispose()
da.Dispose()
End Sub
Private Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
FilePath = FilePath.Replace("~/UploadFile/", "\\172.xx.xx.xxx\wwwroot\NewMS\UploadFile\")
Try
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, IO.FileShare.Read)
Dim Image() As Byte = New Byte(fs.Length) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
objDataRow(strImageField) = Image
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub