How to Create Barcodes for RDLC Reports in .NET Windows Forms
Quick Navigate
- BarcodeLib.Barcode.RDLCReports.dll
- Microsoft .NET Framework 2.0 (or later)
- SQL Server 2005 (any edition) with AdventureWorks Database installed
- Microsoft Visual Studio 2005 or later version
2. Create Barcode Image in RDLC Reports for .NET Windows Forms
-
Create a new Windows Application Project.
- Create a new "Windows Applicaton" project, named "BarcodeforRDLCReports".
-
Add a new DataSet to the project.
- Add a new item (DataSet), named "AdventureWorks.xsd" to the project.
view image
- Drag the "TableAdapter" to your created DataSet. Create a new connection or use existing connection to SQL Server AdventureWorks Sample Database.
view image. Then, click "Next".view image
- Select "Use SQL statements" as the way TableAdapter access the database.
view image
- Use "SELECT ProductID, Name FROM Production.vProductAndDescription WHERE (CultureID = N'en')" as SQL statements.
Click "Finish" button.
view image
- Right click "vProductAndDescription" on the DataSet, and insert a new column in the DataTable, named "Barcode".
view image
- Change "Barcode" data type to "System.Byte[]" (Please input manually if it is necessary). Save the "AdventureWorks.xsd".
view image
-
Add a new Report to the window form.
- Add a new report (Report), named "RDLCReports.rdlc" to the project.
view image
- In Report Items from Toolbox, insert a "Table" to the report.
view image
- In DataSet "AdventureWorks.xsd", add three columns to the report table details section.
view image
- Drag an "Image" item to the last column "Barcode".
view image
- Set image properties "MIMEType" to "image/jpeg", "Source" to "Database", and "Value" to "=Fields!Barcode.Value".
Save the report.
view image
-
Add a Report Viewer to the window form.
- Resize "Form1", and add "ReportViewer" to the form, with the default setting unchanged.
view image
- In "ReportViewer Tasks" window, choose your created report "BarcodeforRDLCReports.RDLCReports.rdlc".
view image
- Bind data collection: In Visual Studio menu bar, choose "Data Sources..." from "Report" tab.
view image
- Select "AdventureWorks.xsd_vProductAndDescription" as data sources. Click "Add to Report", then "OK" button.
view image
- Again, in "ReportViewer Tasks" window, choose "Rebind Data Sources".
view image
- Add "BarcodeLib.Barcode.RDLCReports.dll" to the project reference.
- Add the following code to the "Form1.cs" file.
using System.Data.OleDb;
using System.Drawing.Imaging;
using BarcodeLib.Barcode.RDLCReports;
using BarcodeLib.Barcode;
- Add the following code to the "Form1.cs" file.
private void Form1_Load(object sender, EventArgs e)
{
// load data to the data table
this.vProductAndDescriptionTableAdapter.Fill(this.AdventureWorks.vProductAndDescription);
// create a linear barcode object
LinearRDLC barcode = new LinearRDLC();
// set barcode type to Code 128
barcode.Type = BarcodeType.CODE128;
// draw barcodes for each data row
foreach (AdventureWorks.vProductAndDescriptionRow row in this.AdventureWorks.vProductAndDescription.Rows)
{
// set barcode encoding data value
barcode.Data = row.ProductID.ToString();
// set drawing barcode image format
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
row.Barcode = barcode.drawBarcodeAsBytes();
}
this.reportViewer1.RefreshReport();
}
-
Run the project.
3. Property Settings for Each Barcode Types
Copyright BarcodeLib.com. All rights reserved.
|
|