Generate Barcode Image in Crystal Reports using C#.NET

Detail guide of generating barcode images in Crystal Report using C# class method
Products
Tutorial
Demo now
License & Price
2D Barcode for Crystal
1D Barcode for Crystal
Barcode C# > Barcode in C#
Crystal Report Barcode Library SDK - Overview
Barcode Creator DLL for Crystal Reports is a dynamic .NET component that easily adds barcode functionality and compatibility into C# Crystal Reports in both Windows edition and ASP.NET versions. With the database in C#.NET, users are easy to display barcode images in Crystal Reports without other barcode component or barcode fonts involved.
Terrek provides a variety of solutions step-by-step for generating barcodes in Crystal Reports such as using VB.NET class library to generate barcodes in Crystal Reports, create barcodes in WinForms Crystal Report, print barcodes in ASP.NET Crystal Report.
Prerequisites and Compatibility
Prerequisites
  • Terrek Barcode Generator for Crystal Reports
  • Microsoft .NET Framework 2.0 (or greater)
  • Microsoft Visual Studio 2005 / 2008 / 2010
  • Visual C#.NET (any version)
  • .NET Crystal Reports (runtime support)
Compatibility
  • Visual Basic.NET, Managed C++, Borland Delphi for .NET
  • Windows XP, Windows Vista, Windows 7, Windows Server 2003, Windows Server 2008, etc
  • .NET Framework 2.0, 3.0, 3.5 and above
Generate Barcodes in Crystal Report Windows Version using C#.NET Class Library
  • Download Terrek Barcode Generator for Crystal Reports and unzip
  • Create a new .NET project with "Crystal Reports Application" as template. Name the project as "CrystalReportsBarcode"
  • Create a new report "Using the Report Wizard", and choose "Standard", and click "OK" button
  • In "Data" form, expand "Create New Connection", and expand "ADO.NET"
  • In "Connection" form, select the "CustomerDataSet.xsd" in your downloaded sample dataset package. Then click "Finish" button
  • In "Data" form, add table "Customer" and click "Next"
  • In "Fields" form, add all three columns in the table "Customer". Click "Finish"
  • In CrystalReport1.rpt, drag and drop "Barcode" in the "Field Explorer" to the report Section 3
  • In .NET project "solution explorer", add "Terrek.Barcode.DotNet.dll" to your project reference
  • Copy the following C# code to create barcodes in Crystal Reports in Windows expression (using QR Code as an example)
Sample Code of Generating Barcode Images in Crystal Reports in Windows Forms using C#.NET
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[])));
BarcodeControl qrcode = new BarcodeControl();
qrcode. Symbol = BarcodeSymbol.QRCode;
foreach (DataRow dr in ds.Tables[0].Rows)
{
qrcode.BarcodeData = (int)dr["CustomerId"] + "";
byte[] imageData = barcode.generateBarcodeToByteArray();
dr["Barcode"] = imageData;
}
CrystalReport1 rpt = new CrystalReport1();
rpt.SetDataSource(ds);
this.crystalReportViewer1.ReportSource = rpt;
aConnection.Close();
Generate Barcodes in Crystal Report ASP.NET Version using C#.NET Class Library
  • Download Terrek Barcode Generator for Crystal Reports and unzip
  • Start Visual Studio and create a new Crystal Reports. Then add "Terrek.Barcode.AspNet.dll" to your Crystal Reports project reference
  • Accept the defaults of "Use Report Expert" and "Standard Report" in Crystal Report Gallery dialog box.
  • In the Data tab, expand "Create New Connection" and choose "ADO.NET". After click "next" button, you could see the "Connection" form. Navigate to the "CustomerDataSet.xsd" in the downloaded package and click "Finish" button.
  • Add table "Customer" as selected tables in the "Data" form and click "Next". In following "Fields" form, add all three columns available to right "Customer" fields, and Click "Finish".
  • In CrystalReport1.rpt, drag and drop field "Barcode" to the report Section 3
  • Run the Crystal Report Project (using Code 39 barcode as an example)
Sample Code of Creating Barcode Images in ASP.NET Crystal Report using C#
protected void Page_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[])));
BarcodeControl barcode = new BarcodeControl();
barcode. Symbol = BarcodeSymbol.Code39;
foreach (DataRow dr in ds.Tables[0].Rows)
{
barcode.BarcodeData = (int)dr["CustomerId"] + "";
byte[] imageData = barcode.drawBarcodeAsBytes();
dr["Barcode"] = imageData;
}
CrystalReportSource1.ReportDocument.Load(Server.MapPath
("CrystalReport1.rpt"));
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);
CrystalReportSource1.DataBind();
aConnection.Close();
}