Crystal Reports Barcode Generator Tutorial
Crystal Reports Barcode integrates barcodes into Crystal Reports. It can create, generate linear and 2D barcodes in Crystal Reports. And it is the most affordable .NET barcode generator for barcode .NET professionals.
Crystal Reports Barcode Generator
Crystal Reports Barcode supports 70+ linear (1d) and matrix (2d) barcode standards, like:
- 2D Barcodes: Data Matrix, PDF417 and QR Code.
- Alphanumeric Barcodes: Code 39 Extended code 39, Code 93 Extended code 93, Code 128 and EAN/UCC-128(GS1-128).
- UPC / EAN Barcodes: EAN 8 EAN 2, EAN 5 supplemental barcodes, EAN 13 EAN13+2, EAN13+5 supplemental barcodes, ISBN, ISSN, UPC-A and UPC-E.
- Numeric Barcodes: Codabar, Code 11 and MSI Plessey.
- Code 2 of 5 based Barcodes: Standard 2of5, Interleaved 2of5 and ITF14.
- Postal Barcodes: Identcode, Leitcode, POSTNET (Postal barcode), PLANET, Intelligent Mail Barcode (USPS OneCode) and Customer Barcode (RM4SCC).
Tutorial for Barcode Generation in Crystal Reports
This tutorial demonstrates how to add barcodes into Crystal Reports report with the .NET Barcode SDK in .NET framework application. In the tutorial, we create a dataset and insert a new field to take the barcode image. Then we will compose a few lines code in C# to process rows in the dataset and generate barcode images from the inserted field when load the Crystal Reports application.
We are going to use the barcode library to create barcode images for Crystal Reports report in Microsoft Visual Studio 2005 in the below demonstration.
- Start Microsoft Visual Studio 2005. Create a Crystal Reports application by choosing File>New>Project. Select the Crystal Reports Application template and change the default name as KD Sample Crystal Reports
- Create a "Standard" report with "Using the Report Wizard" and click "OK"
- In "Data" window, expand "Create New Connection" and "ADO.NET" respectively
- In the poped up window, locate "Demo.xsd" in your evaluation package, and then click "Finish"
- Then you will find an item "Table" under NewDataSet. Drag it to the Textbox of Selected Tables. Click Next
- Drag Table from Available Fields to Fields to Display. Then you will find two new items (Table.ID & Table.Beverages). Click Next, then select Finsh
- A CrystalReport1.rpt will be visible. Add a new column by clicking Field Explorer and drag KDBarcode from the Table under Database Fields to the CrystalReport1.rpt.
- please add "KeepDynamic.Barcode.CrystalReport.dll" to your project reference
- Switch to Design view, open Form1.cs, double click the form, and enter Form1.cs
- Copy the following C# code into the method Form1_Load, and then run the project
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Demo/kd/Demo.mdb" );
aConnection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("select * from Beverages", aConnection);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
//Add a new column named "KDBarcode" to the DataSet, the new column data type is byte[]
ds.Tables[0].Columns.Add(new DataColumn("KDBarcode", typeof(byte[])));
BarCode barcode = new BarCode();
barcode.SymbologyType = SymbologyType.Code128;
foreach (DataRow dr in ds.Tables[0].Rows)
{
barcode.CodeText = dr["Beverages"] + "";
byte[] imageData = barcode.drawBarcodeAsBytes();
dr["KDBarcode"] = imageData;
}
CrystalReport1 rpt = new CrystalReport1();
rpt.SetDataSource(ds);
this.crystalReportViewer1.ReportSource = rpt;
aConnection.Close();
}