How to add an image in RDLC Report
Mainly three ways we can add image in Rdlc Report
B) External
C) Database
Create a Project and open your Form. Drag a Reportviewer from ToolBox
to your form
A) Embedded
a. Add Rdlc report to your project
b. Add image to Rdlc report from toolbox(Image Properties Popup will Display)
C.Select Embedded Mode from image sourse List
d. Click import button and import an image to Rdlc
Imports System.IO
Imports Microsoft.Reporting.WinForms
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Embedded Mode
ReportViewer1.LocalReport.ReportPath = "Full path of RDLC"
Me.ReportViewer1.RefreshReport()
End Sub
Run your Project You can see image in your Report
B) External
Fisrt we want to add Parameter in Rdlc Report
a. Select "View" menu from top
b. select "Report Data" from "View" menu
c. Right Click on the Parameters folder from "Report Data"
d. Select "Add Parameter"
e. Click Ok Button to add Parameter(If you want you can change parameter name)
f. Add another image in Rdlc report(Image Properties Popup will Display)
g. Select External Mode from image sourse List
h. Click fx button on the Popup(Expression ppopup will Display)
i. Select Parameters from category list from left side
j. Double Click on the newly added parameter from values list
k. Click Ok to Close popup, Click ok button in Image Properties Popup also
Retrun to your form and add this code :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Embedded Mode
ReportViewer1.LocalReport.ReportPath = "Full path of RDLC"
'External Mode
Dim r(0) As ReportParameter
r(0) = New ReportParameter("rpt_img", "File:\" + "Full Path of image", True)
Me.ReportViewer1.LocalReport.EnableExternalImages = True
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {r(0)})
Me.ReportViewer1.RefreshReport()
End Sub
Run your Project You can see image in your Report
C) Database
Fisrt we want to add Dataset in Rdlc Report
a. Select "Project" menu from top
b. select "Add New Item" from "Project" menu
c. Right Click on the Dataset and add a new dataTable
d. Right Click on the DataTable and add a Column (change column name as 'img' for easy use)
e. Go to rdlc report, add a new dataset
f. write name for dataset and select newly created dataset from list
g. Click ok to save
h. Add another image in Rdlc report(Image Properties Popup will Display)
i. Select Database Mode from image sourse List
j. Click fx button near the use this field(Expression ppopup will Display)
k. Select Datsets from category list from left side
l. Double Click on the field name from values list(right side)
m.Select MIME type
m.Select MIME type
n. Click Ok to save and Close popup
Retrun to your form and add this code :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Embedded Mode
ReportViewer1.LocalReport.ReportPath = "Full path of RDLC"
'External Mode
Dim r(0) As ReportParameter
r(0) = New ReportParameter("rpt_img", "File:\" + "Full Path of image", True)
Me.ReportViewer1.LocalReport.EnableExternalImages = True
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {r(0)})
'Database Method
Dim ds As DataSet = 'select binary image data from table .Column name must same as datafield use in Rdlc Report'
Dim datas As New ReportDataSource("use your dataset name", ds.Tables(0))
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
Me.ReportViewer1.LocalReport.DataSources.Add(datas)
Me.ReportViewer1.RefreshReport()
End Sub
'Embedded Mode
ReportViewer1.LocalReport.ReportPath = "Full path of RDLC"
'External Mode
Dim r(0) As ReportParameter
r(0) = New ReportParameter("rpt_img", "File:\" + "Full Path of image", True)
Me.ReportViewer1.LocalReport.EnableExternalImages = True
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {r(0)})
'Database Method
Dim ds As DataSet = 'select binary image data from table .Column name must same as datafield use in Rdlc Report'
Dim datas As New ReportDataSource("use your dataset name", ds.Tables(0))
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
Me.ReportViewer1.LocalReport.DataSources.Add(datas)
Me.ReportViewer1.RefreshReport()
End Sub
No comments:
Post a Comment