Our Customers
Contact Us Email: support@barcodelib.com
Home > .NET Crystal Reports Barcode > .NET, C#, VB.NET Barcode Componenet for Crystal Reports for .NET WinForms
Download Barcode for Crystal Reports Trial

How to Generate Barcode Images using Crystal Reports for .NET in .NET Windows Applications

  • BarcodeLib.Barcode.CrystalReports.dll
  • Microsoft .NET Framework 2.0 (or later)
  • Crystal Report for Visual Studio .NET 2010
Create Barcode Image in Crystal Reports for .NET Windows Forms
  1. Create a new Windows Application Project.
    • Create a new project using "Crystal Reports Application" as template, named "BarcodeforCrystalReports".
  2. Add a Crystal Report item to the project.
    • Add a new item (Crystal Report), named "CustomerReport.rpt" to the project. view image
    • Select Expert as "Mail Label". Click "OK" button. view image
    • In "Mailing Labels Report Creation Wizard", click "Create New Connection", and expand "ADO.NET". view image
    • In "ADO.NET" form, select "CustomerDataSet.xsd" file in your downloaded package, and click "Finish" button. view image
    • In "Mailing Labels Report Creation Wizard", add table "Customer" under "ADO.NET", to selected table. And click "Next" button. view image
    • Add all three fields "ID", "CustomerId", "CustomerName", to "Fields to Display:". Click "Next". view image
    • Select default label "Return Address (Avery 5267)", and click "Finish" button.
    • Now you can view the report template, and find that field "Barcode" not in the report template. view image
    • Re-arrange the report template. view image
    • Drag field "Barcode" to the report template. And Right click "Barcode" object, select "Format Object" menu. view image
    • In "Format Editor" form, check "Can Grow" property. view image
  3. Add Crystal Report Viewer to the window form.
    • Resize "Form1", and add "CrystalReportViewer" to the form, with the default setting unchanged. view image
    • Add a reference to BarcodeLib.Barcode.CrystalReports.dll.
    • Add the following code to the Form1.cs file.
     using System.Data.OleDb;
using System.Drawing.Imaging;
using BarcodeLib.Barcode.CrystalReports;
using BarcodeLib.Barcode;

private void Form1_Load(object sender, EventArgs e)
//create the database connection. Please change to correct data file (BarcodeDemoData.mdb) path.
OleDbConnection aConnection = new OleDbConnection(
Data Source=C:/BarcodeLib_NETBarcode_Trial/ReportingData/BarcodeDemoData.mdb"

OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT * FROM Customer", aConnection);
DataSet ds = new DataSet();

//Add the Barcode column to the DataSet
ds.Tables[0].Columns.Add(new DataColumn("Barcode", typeof(byte[])));

//Create an instance of Linear Barcode
//Use DataMatrixCrystal for Data Matrix
//Use PDF417Crystal for PDF417
//Use QRCodeCrystal for QR Code
LinearCrystal barcode = new LinearCrystal();
//Barcode settings
barcode.Type = BarcodeType.CODE128;
barcode.BarHeight = 50; //50 pixel
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

foreach (DataRow dr in ds.Tables[0].Rows)
barcode.Data = (int)dr["CustomerId"] + "";
byte[] imageData = barcode.drawBarcodeAsBytes();
dr["Barcode"] = imageData;

CustomerReport rpt = new CustomerReport();

this.crystalReportViewer1.ReportSource = rpt;

//close the connection Its important.

3. Run the project.
Related .NET Barcode Generator Controls