Home > .NET RDLC Reports Barcode > .NET, C#, VB.NET Barcode DLL for RDLC Reports for .NET WinForms

How to Generate Barcodes with RDLC Reports in .NET Windows Applications?


This document provides a detailed step-by-step procedure for utilizing the BarcodeLib C# RDLC Report Barcode Generator library to produce and print barcode images within local reports in Windows Forms application (.net framework).



Prerequisites

  • BarcodeLib.Barcode.RDLCReports.dll
  • Microsoft .NET Framework 4.x, 3.x, 2.x
  • Microsoft Visual Studio 2026, 2022, 2019, 2017, or early version


1. Create a New Windows Forms Project

  1. Launch Visual Studio 2022 and select Create a new project.
  2. In the project template dialog, choose Windows Forms App (.NET Framework) and click the Next button.

  3. Name the project BarcodeLibRDLCBarcodeWinFormsDemo.

  4. After creation, verify that all auto-generated files are visible in the Solution Explorer.


2. Add Required Libraries and NuGet Packages

  1. In the Solution Explorer, right-click References and select Manage NuGet Packages.
  2. Click Browse and use the search control to locate Microsoft.ReportingServices.ReportViewerControl.Winforms from the package source nuget.org.
  3. Install the latest stable version of the above package.

  4. Add BarcodeLib RDLC barcode library dll BarcodeLib.Barcode.RDLCReports.dll to the project reference.
  5. Confirm successful installation by inspecting the References node in the Solution Explorer.



3. Print Barcodes from a DataTable in RDLC Report Using C#

3.1 Add a Data Source

  1. Add a new item of type DataSet1.xsd to the project.

  2. Inside `DataSet1.xsd`, add a new data table. The default table name is DataTable1.

  3. Add a column to DataTable1 with the name Website and set its Data Type property to System.String.

  4. Add a second column named Barcode and set its Data Type property to System.Byte[].
  5. The resulting DataTable1 contains exactly two columns as described.

3.2 Design the RDLC Report Template

  1. Add a new report item named Report1.rdlc to the project.

  2. Change the Copy to Output Directory property to Copy if newer.

  3. Right click Datasets and select Add Dataset to open the Dataset Properties dialog.
  4. In the dialog, choose DataSet1 from the Data source combo-box and DataTable1 from the Available datasets combo-box.

  5. Insert a Table control into the report designer.
  6. Drag the fields Website and Barcode into the table within the report designer.

  7. Insert an Image control into the Barcode field and configure its properties as follows:
    • In Image Properties dialog, set the image source to Database.
    • Set the Use this field to [Barcode]
    • For MIME type, select image/png
  8. Finally, adjust the table row height and column width to appropriate dimensions.

3.3 Add Report Viewer Control to the Windows Form

  1. Double-click Form1.cs to open the designer and add a ReportViewer control to the form.
  2. Select the report BarcodeLibRDLCBarcodeWinFormsDemo.Report1.rdlc for this viewer control.

  3. From the menu, choose View Code to open the Form1.cs code window.

3.4 Replace Code-Behind Contents

Replace all existing content in Form1.cs with the following C# code:

using BarcodeLib.Barcode;
using BarcodeLib.Barcode.RDLCReports;
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeLibRDLCBarcodeWinFormsDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //  Prepare report data.
            DataTable dt = new DataTable();
            dt.Columns.Add("Website", typeof(String));
            dt.Columns.Add("Barcode", typeof(byte[]));

            String site1 = "https://www.barcodelib.com";
            String site2 = "https://www.google.com";
            String site3 = "https://www.youtube.com";

            //  Create data for the 1st row in the table.
            LinearRDLC barcode = new LinearRDLC();
            barcode.Type = BarcodeType.CODE128;
            barcode.ResizeImage = true;
            barcode.ImageWidth = 300;
            barcode.ImageHeight = 200;
            barcode.ImageFormat = ImageFormat.Png;

            barcode.Data = site1;
            byte[] imgData = barcode.drawBarcodeAsBytes();
            dt.Rows.Add(site1, imgData);

            //  Create data for the 2nd row in the table.
            barcode.Data = site2;
            imgData = barcode.drawBarcodeAsBytes();
            dt.Rows.Add(site2, imgData);

            //  Create data for the 3rd row in the table.
            barcode.Data = site3;
            imgData = barcode.drawBarcodeAsBytes();
            dt.Rows.Add(site3, imgData);


            //  Configure Report
            this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));


            this.reportViewer1.RefreshReport();
        }
    }
}


4. Run the RDLC Report in the Windows Forms Application

  1. The barcode in RDLC report is now complete. Press Ctrl+F5 to execute the Windows Forms project.
  2. The Windows Forms application will display the RDLC report containing barcode images generated from the DataTable.

Related .NET Barcode Generator SDKs