Barcode for RDLC > Generate Barcode in C#

How to Generate Barcodes in RDLC Using C#.NET

Encoding, Adjusting &Printing Barcodes for RDLC Reports in C#.NET IDEs
KA.Barcode for RDLC Reports Overview
KeepAutomation Barcode Generator for RDLC is a standard and powerful barcode component that lets you integrate barcode generation and printing features into RDLC Reports. The easy-to-use .NET SDK could be managed in .NET with Visual C#. Windows applications as well as ASP.NET Web Forms are supported. This page will show you how to generated barcodes in RDLC using C#.NET.
Compatibility & Requirements
  • .NET Development Environments: Visual Studio 2005/2008 /2010 installed, .NET Version greater than 2.0, C#.NET & VB.NET
  • Compatible Operating Systems: Windows 2000, XP, Vista, and Windows 7
  • Minimum System Requirements: 500 MHZ processor, 128 MB RAM, 5 MB available hard drive space
Test Environment
  • Microsoft Windows XP
  • Microsoft Visual Studio 2005
  • Visual C#.NET
How to Generate Barcodes in RDLC in WinForms Using C#
  1. Open your Visual Studio and create a new WinForms project, then create a "DataSet" with the name "AdventureWorks.xsd".
  2. Drag "TableAdapter" item under the "Toolbox" to the new "DataSet".
  3. Link the connection to SQL Server AdventureWorks Sample Database.
  4. Copy "SELECT ProductID, Name FROM Production.vProductAndDescription WHERE (CultureID = N'en') " as SQL Statement.
  5. Right-click "vProductAndDescription" on the dataset to create a column (named as "Barcode"), and change the data type to "System.Byte[]" in "Properties" window.
  6. Go to "Solution Explorer" and create a new "Report" item.
  7. Insert a table to your report and add three columns in the dataset to the report table details section.
  8. Drag and drop "Image" item to the last column and name it "Barcode".
  9. Change "Source", "MIMEType", "Value" to "Database", "image/jpeg", "=Fields!Barcode.Value" respectively through "Properties" window.
  10. Drag "ReportViewer" under "Toolbox" to Form1.
  11. Click "Report1.rdlc[Design]", then click "Report" and choose "Data Sources....", click "Add to Report" & lastly click "OK".
  12. Add reference "KeepAutomation.Barcode.RDLC.dll" to your project.
  13. Right click "Form1.cs" and select "View Code", then compile the following sample code.
  14. Use "KeepAutomation.Barcode.RDLC" namespace and debug.
C# Sample code
     private void Form1_Load(object sender, EventArgs e)
{
// load data to the data table this.vProductAndDescriptionTableAdapter.Fill
this.vProductAndDescriptionTableAdapter.Fill(this.AdventureWorks.vProductAndDescription);
// create a linear barcode object
BarCode barcode = new BarCode();
// set barcode type
barcode.Symbology = KeepAutomation.Barcode.Symbology.Code11;
// draw barcodes for each data row
foreach (AdventureWorks.vProductAndDescriptionRow
row in this.AdventureWorks.vProductAndDescription.Rows)
{// set barcode encoding data value
barcode.CodeToEncode = row.ProductID.ToString();
// set drawing barcode image format
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

row.Barcode = barcode.generateBarcodeToByteArray();
}
this.reportViewer1.RefreshReport();
}
How to Generate Barcodes in RDLC in Web Forms Using C#
  1. Open your Visual Studio and create a website project, and add "KeepAutomation.Barcode.RDLC.dll" to reference.
  2. Right click your project In "Solution Explorer" to add a new "Class" item.
  3. Copy the sample code into the "Class" item. Go to "Build" tab and choose "Build Web Site".
  4. Go to "Solution Explorer" and right click your web project to add a new "Report" item.
  5. Go to "Toolbox" and drag "Table" in "Report Items" to the report. Then, go to "Website Data Sources" tab and insert "BarcodeName" and "BarcodeId".
  6. Insert "Image" item to the last column and name it as "Barcode".
  7. Revise "Source" to "Database", "MIMEType" to "image/jpeg", "Value" to "=Fields!Byte.Value" respectively in "Properties" window.
  8. In "Solution Explorer", right click "Default.aspx" and select "View Designer" to add a "ReportViewer" to the project
  9. Choose your created report and run your ASP.NET web project.
C# Sample code
     public class BarocdeDemo
{

private string m_barcodeName;
private int m_barcodeId;
private byte[] m_byte;
public BarocdeDemo(string barcodeName, int barcodeId, string data)
{
m_barcodeName = barcodeName;
m_barcodeId = barcodeId;
BarCode barcode = new BarCode();
barcode.Symbology = KeepAutomation.Barcode.Symbology.EAN13;
barcode.CodeToEncode = data;
m_byte = barcode.generateBarcodeToByteArray();
}
public byte[] Byte
{
get { return m_byte; }
}
public string BarcodeName
{
get { return m_barcodeName; }
}
public int BarcodeId
{
get { return m_barcodeId; }
}
}
public class Merchant
{
private List<BarocdeDemo> m_barcodes;
public Merchant()
{
m_barcodes = new List<BarocdeDemo>();
m_barcodes.Add(new BarocdeDemo("code11", 001, "code11"));
m_barcodes.Add(new BarocdeDemo("code25", 002, "code25"));
m_barcodes.Add(new BarocdeDemo("code39", 003, "code39"));
m_barcodes.Add(new BarocdeDemo("code93", 004, "code93"));
m_barcodes.Add(new BarocdeDemo("code128",005, "code128"));
m_barcodes.Add(new BarocdeDemo("upcean", 006, "upcean"));
}
public List<BarocdeDemo> GetProducts()
{
return m_barcodes;
}
}
CompatibilityTest EnvironmentFor Windows C#For Web C#Using C#Using VB.NETUsing ASP.NETUsing .NET WinformsData Matrix for RDLCPDF417 for RDLCQR Code for RDLCmoreCodabar for RDLCCode 39 for RDLCCode 128 for RDLCEAN-8 for RDLCEAN-13 for RDLCEAN 128 for RDLCIntelligent Mail for RDLCInterleaved 2 of 5 for RDLCISBN for RDLCITF-14 for RDLCRM4SCC for RDLCUPC-A for RDLCUPC-E for RDLCmore
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.