【问题标题】:Dynamic images in VB.NET 2005 Crystal ReportVB.NET 2005 Crystal Report 中的动态图像
【发布时间】:2018-03-28 06:15:47
【问题描述】:

我正在使用 VB.NET 2005。我需要将图片插入到水晶报表中我已将图片的路径存储在我的数据库中。我的水晶报表版本中没有图形位置选项。怎么可能

【问题讨论】:

标签: vb.net crystal-reports


【解决方案1】:

如果您的数据源是数据表,请添加一个 Byte() 类型的新列,如下所示:

Dim image As New DataColumn
With image
    .ColumnName = "photo"
    .DataType = GetType(Byte())
    .AllowDBNull = True
End With
yourTable.Columns.Add(image)

现在根据存储在数据源中的路径设置图像的值。 (您应该在检索数据时包含存储图像路径的列。)

For Each row As DataRow in yourTable.Rows
   row("photo") = GetImageData(row("path_to_photo"))
Next
yourTable.AcceptChanges()



Private Function GetImageData(ByVal cFileName As String) As Byte()
    Dim fs As System.IO.FileStream = _
            New System.IO.FileStream(cFileName, _
            System.IO.FileMode.Open, System.IO.FileAccess.Read)
    Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs)
    Return (br.ReadBytes(Convert.ToInt32(br.BaseStream.Length)))
End Function

然后将 yourTable 设置为报表的数据源

yourReport.SetDataSource(yourTable)

当然,您的水晶报表定义的数据源必须与您传递给它的数据源相匹配。将“照片”列拖到您的报告中,应该会显示照片。

【讨论】:

  • 有没有办法不将图像存储在数据库中。
  • 它不是数据库。只是一个数据表。我没有看到任何其他方法
猜你喜欢
  • 2016-06-05
  • 2010-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-04
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多