I have the following code,
Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Dim cryrpt As New ReportDocument
Dim fs As FileStream
Dim br As BinaryReader
Dim dt As New DataTable
Dim rptobj As New CrystalReport1
Dim drow As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cryrpt.Load("E:\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")
Dim Connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\bbs_Excel\BBS.accdb")
Dim strSQL As String = "Select shape_code,bend_shape,A From data"
Dim DA As New OleDbDataAdapter(strSQL, Connection)
Dim DS As New DataSet
DA.Fill(DS, "data")
Dim rows As Integer = DS.Tables(0).Rows.Count
dt.Columns.Add("shape_code", System.Type.GetType("System.Int32"))
dt.Columns.Add("bend_shape", System.Type.GetType("System.Byte[]"))
dt.Columns.Add("A", System.Type.GetType("System.Int32"))
For i = 0 To rows - 1
Try
drow = dt.NewRow
If File.Exists(DS.Tables(0).Rows(i)(1)) Then
fs = New FileStream(DS.Tables(0).Rows(i)(1), FileMode.Open)
End If
br = New BinaryReader(fs)
Dim imgbyte(fs.Length) As Byte
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
drow(0) = DS.Tables(0).Rows(i)(0)
drow(1) = imgbyte
drow(2) = DS.Tables(0).Rows(i)(2)
dt.Rows.Add(drow)
br.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
If dt.Rows(i)(0) = "0" Then
CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject).ObjectFormat.EnableSuppress = False
With CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject)
.Left = 0 * 1440
.Top = 0.14 * 1440
.Width = 0.16 * 1440
.Height = 0.25 * 1440
End With
Else
End If
Next
rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj
End Sub
End Class
Problem is the field object is not getting formatted. It is getting displayed as it is on the report.
Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Dim cryrpt As New ReportDocument
Dim fs As FileStream
Dim br As BinaryReader
Dim dt As New DataTable
Dim rptobj As New CrystalReport1
Dim drow As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cryrpt.Load("E:\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")
Dim Connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\bbs_Excel\BBS.accdb")
Dim strSQL As String = "Select shape_code,bend_shape,A From data"
Dim DA As New OleDbDataAdapter(strSQL, Connection)
Dim DS As New DataSet
DA.Fill(DS, "data")
Dim rows As Integer = DS.Tables(0).Rows.Count
dt.Columns.Add("shape_code", System.Type.GetType("System.Int32"))
dt.Columns.Add("bend_shape", System.Type.GetType("System.Byte[]"))
dt.Columns.Add("A", System.Type.GetType("System.Int32"))
For i = 0 To rows - 1
Try
drow = dt.NewRow
If File.Exists(DS.Tables(0).Rows(i)(1)) Then
fs = New FileStream(DS.Tables(0).Rows(i)(1), FileMode.Open)
End If
br = New BinaryReader(fs)
Dim imgbyte(fs.Length) As Byte
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
drow(0) = DS.Tables(0).Rows(i)(0)
drow(1) = imgbyte
drow(2) = DS.Tables(0).Rows(i)(2)
dt.Rows.Add(drow)
br.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
If dt.Rows(i)(0) = "0" Then
CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject).ObjectFormat.EnableSuppress = False
With CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject)
.Left = 0 * 1440
.Top = 0.14 * 1440
.Width = 0.16 * 1440
.Height = 0.25 * 1440
End With
Else
End If
Next
rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj
End Sub
End Class
Problem is the field object is not getting formatted. It is getting displayed as it is on the report.