Barcode for Crystal Report > Generate Barcode in .NET WinForms

Create Barcodes in Crystal Reports in WinForms

Detail Guide of Barcode Generation in Crystal Reports in WinForms
KA.Barcode for Crystal Reports Overview
Developers can use KeepAutomation Barcode Generator for Crystal Reports to add barcode features to Crystal Reports in Web Forms and WinForms. The generated barcodes can be saved in Gif, Tiff, Bmp, Png & Jpeg image file formats or to Bitmap, Stream, or Graphic objects.
Compatibility & Requirements
  • Development Environments: Microsoft Visual Studio 2005, 2008 and 2010, .NET language environment such as Visual C#, Visual Basic.NET, Crystal Report for .NET (runtime), .NET Framework environment 2.0, 3.0, 3.5, 4.0
  • Applicable Operating Systems: Windows Vista/Windows 7/Windows XP/Window Server 2005/2008
Test Environment
  • Microsoft Windows XP
  • Microsoft Visual Studio 2005
  • Visual Basic & C#.NET
How to Generate Barcodes in Crystal Reports in WinForms
Concise Description of Demo Package
Unzip the demo package and open the demo dataset "KACrystalData.mdb". You will see a table named "Product", including three columns ("ID", "ProductId", "ProductName").

There is a ProductDataSet.xsd file for "KACrystalData.mdb". It is used to define four columns ("ID", "ProductId", "ProductName", "Barcode").
Generate Barcodes in Crystal Reports in WinForms
  1. Create a new .NET WinForms project with "Crystal Reports Application" as template.
  2. In "Crystal Reports Gallery" form, choose "Standard" and click "OK" button.
  3. In "Data" form, expand "Create New Connection", then expand "ADO.NET".
  4. In "Connection" form, go to your unzipped package and select "ProductDataSet.xsd". Then click "Finish" button.
  5. In "Data" form, add "Table" item to the blank area on the right side and click "Next".
  6. In "Fields" form, add all three columns under "Table" item to the blank area on the right side and click "Finish".
  7. In CrystalReport1.rpt, drag and drop "Barcode" in the "Field Explorer" to the report Section 3.
  8. In .NET project "Solution Explorer", add "KeepAutomation.Barcode.Crystal.dll" to your project reference.
  9. Open your "Form1.cs" and copy the following code into it.
  10. Run your project to see the generated barcode images.
C# Sample code
     OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/KACrystalData.mdb");
aConnection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("select * from Product", 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[])));
BarCode barcode = new BarCode();
barcode.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto;
foreach (DataRow dr in ds.Tables[0].Rows)
{
barcode.CodeToEncode = (int)dr["ProductId"] + "";
byte[] imageData = barcode.generateBarcodeToByteArray();
dr["Barcode"] = imageData;
}
CrystalReport1 rpt = new CrystalReport1();
rpt.SetDataSource(ds);
this.crystalReportViewer1.ReportSource = rpt;
aConnection.Close();

VB Sample code
     Dim aConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/KACrystalData.mdb")
aConnection.Open()
Dim dataAdapter As New OleDbDataAdapter("select * from Product", aConnection)
Dim ds As 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", GetType(Byte())))
Dim barcode As New BarCode()
barcode.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto
For Each dr As DataRow In ds.Tables(0).Rows
barcode.CodeToEncode = CInt(dr("ProductId")) & ""
Dim imageData As Byte() = barcode.generateBarcodeToByteArray()
dr("Barcode") = imageData
Next
Dim rpt As New CrystalReport1()
rpt.SetDataSource(ds)
Me.crystalReportViewer1.ReportSource = rpt
aConnection.Close()

CompatibilityTest EnvironmentWindows Crystal ReportsUsing C#Using VB.NETUsing ASP.NETUsing .NET WinformsData Matrix for Crystal ReportPDF417 for Crystal ReportQR Code for Crystal ReportmoreCodabar for Crystal ReportCode 39 for Crystal ReportCode 128 for Crystal ReportEAN-8 for Crystal ReportEAN-13 for Crystal ReportEAN 128 for Crystal ReportIntelligent Mail for Crystal ReportInterleaved 2 of 5 for Crystal ReportISBN for Crystal ReportITF-14 for Crystal ReportRM4SCC for Crystal ReportUPC-A for Crystal ReportUPC-E for Crystal Reportmore
KeepAutomation provides complete barcode automation solutions for add barcode display 2-dimensional, barcode generation capacity api, and barcode mobile applications. We recommend the customers use high quality ASP.NET html5 document viewer, c# pdf sdk, C# merge PDF files, Split PDF in C#, C# View, edit PDF online , C# Convert PDF to Tiff, C# Convert PDF to text, txt, .net imaging sdk, C# PDF metadata edit from RasterEdge.com.