Generate, Print Barcode in Crystal Reports using C#.NET

How to create, print barcode label images in Crystal Reports for ASP.NET web app and Windows Forms application with free C# barcode example source code

Using Free C# Souce Code to Generate Barcode Labels for ASP.NET Web Application & IIS Projects







In this C# tutorial, you learn how to generate barcode images in Crystal Reports using C# code.

  • Generate barcode in Crystal Reports for .NET project
  • Print barcode through IIS web streaming in Crystal Reports
  • Barcode image with transparent background
  • Barcode data with non-printable chars
  • Barcode for GS1 data message encoding
  • Barcode for international text encoding

How to create linear, 2d barcodes in Crystal Reports using C#

  1. Download .NET Barcode Generator Suite
  2. Install C# library to create barcodes in Crystal Reports
  3. Step by Step Tutorial














How to Generate, Print Barcode Label in Crystal Reports using C#

Top

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.







How to Steam Barcodes in Crystal Reports using C#

Top
  1. Create a new report in your Crystal Reports
  2. In your Crystal Reports report, click menu Insert, click menu OLE Object....



  3. Choose Bitmap Image as Object Type, and check Display As Icon. Click "OK".



  4. Place the bitmap image icon to the right location you need print barcode in your report. Close the Paint application popped.

  5. Right click the bitmap image icon, and click menu Format Graphics...



  6. Go to Picture tab, and click the icon next to Graphic Location:



  7. In the formula windows, input "http://azuredemo.onbarcode.com/linear.aspx?TYPE=7&DATA=" + ToText({Customer.CustomerId}, "#")

    http://azuredemo.onbarcode.com/linear.aspx?TYPE=7&DATA= is OnBarcode Online Barcode Generator Hosting Service URL format, if you are streaming barcodes using Java Barcode Generator Web Application or ASP.NET Barcode Generator Web Application, please change the url.

    Customer is the table name, CustomerId is the column name.

    Here we are printing Code 128 barcodes on the report with CustomerId as barcode encoding data.



  8. Save and close the "Format Editor" window.
  9. Now you can preview the report with barcode Code128 printed.







C#.NET Barcode Generation Guide for Supported Barcode Images

Top

.NET Barcode Control DLL for C# - Barcodes Generation













OnBarcode is a market-leading provider of barcode imaging 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 comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.