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