Add impage into Web Crystal Report

G

Guest

Hi,

I created a web form and add a crystalviewer into it, and I create a dataset
of two columns: name (string) and img (byte) and using following codes to
assign the img field by opening a image file stored in the server. But when I
run the report, it returned an error:
System.InvalidCastException: Specified cast is not valid.
at System.Convert.ToSByte(Object value)
at System.Data.Common.SByteStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't
store <System.Byte[]> in Logo Column. Expected type is SByte.

There is no sbyte for a ds field. If anybody can give some suggestion, I
appreciate.

------ Codes ------------
Dim ds As New MyDataSet
Dim row As DataRow
Dim fname As String = SystemConfig.APPL_PHYSICAL_PATH & "MyImageFileName"

row = ds.Tables(0).NewRow()

row(0) = "FirstImage"
row(1) = GetImageData(fname)

crReportDocument = New rpt_CoverLetter
crReportDocument.SetDataSource(ds)
CrystalReportViewer1.ReportSource = crReportDocument

Private Function GetImageData(ByVal fileName As String) As Byte()

Dim fs As System.IO.FileStream = New System.IO.FileStream(fileName,
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top