Generate and Print Barcodes Crystal Reports using .NET Barcode Generator



This document explains how to use .NET Barcode Generator to generate and print barcodes on Crystal Reports report documents.

We provides several methods to generate and print barcodes in Crystal Reports. Please read our Crystal Reports Barcode Integration Guide for more information.  

How to generate & print barcodes in your Crystal Reports using .NET Barcode Generator?

Download Demo Package

  1. Download .NET Barcode Generator for Crystal Reports for .NET

Brief Introduction

  1. In our demo dataset "BarcodeDemoData.mdb", there is a table "Customer", with three columns inside: "ID", "CustomerId", "CustomerName".

  2. There is a CustomerDataSet.xsd file for "BarcodeDemoData.mdb", which defines all above three columns in Customer table, also define one extra column named "Barcode", with data type "xs:base64Binary".

  3. In the following example, we will show you how to display all three column data and also with the extra barcode column which displays Code 128 barcode with "CustomerId" value encoded.


Demonstration

  1. Create a new .NET project with "Crystal Reports Application" as template. Name the project as "CrystalReportsBarcode"



  2. Create a new report "Using the Report Wizard", and choose "Standard", and click "OK" button.

  3. In "Data" form, expand "Create New Connection", and expand "ADO.NET".



  4. In "Connection" form, select the "CustomerDataSet.xsd" in your downloaded sample dataset package. Then click "Finish" button.



  5. In "Data" form, and add table "Customer". Then click "Next".



  6. In "Fields" form, add all three columns in the table "Customer". Click "Finish".



  7. In CrystalReport1.rpt, add field "Barcode" to the report Section 3 (Details)



  8. In your .NET project solution explorer, add "OnBarcode.Barcode.WinForms.dll" to your project reference.

  9. Open your Form1.cs in Design view, double click the form, enter Form1.cs.



  10. Copy the following code into the method Form1_Load
    private void Form1_Load(object sender, EventArgs e)
    {
    OleDbConnection aConnection = new OleDbConnection(
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Demo/BarcodeDemoData.mdb");
    aConnection.Open();
    OleDbDataAdapter dataAdapter = new OleDbDataAdapter("select * from Customer", aConnection);
    DataSet ds = new DataSet();
    dataAdapter.Fill(ds);
    //add a new column named "Barcode" to the DataSet, the new column data type is byte[]
    ds.Tables[0].Columns.Add(new DataColumn("Barcode", typeof(byte[])));
    Linear barcode = new Linear();
    barcode.Type = BarcodeType.CODE128;
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
    barcode.Data = (int)dr["CustomerId"] + "";
    byte[] imageData = barcode.drawBarcodeAsBytes();
    dr["Barcode"] = imageData;
    }
    CrystalReport1 rpt = new CrystalReport1();
    rpt.SetDataSource(ds);
    this.crystalReportViewer1.ReportSource = rpt;
    aConnection.Close();
    }
    
  11. Run the report.







OnBarcode is a market-leading provider of barcode generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides high quality tutorials and guides for various linear, 2d barcode information, such as C# Barcode, QR Code C#, QR Code VB.NET, QR Code ASP.NET, QR Code .NET, ASP.NET Barcode. OnBarcode products support most common barcode symbologies including QRCode C# SDK, Data Matrix in C#.net Control, PDF-417 Componennt in C# .NET, Code 128 VS .net sdk, Code 39 C# library.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.