Tutorial for Barcode Generation in Local Reports (RDLC)


In this article, you will learn how to generate barcode images in a RDLC report by using our .NET barcode library.
The following requirements are necessary for our tutorial of generating barcodes in a new client report definition (.rdlc) file, a local report.
- Start Visual Studio 2005 and create a new Windows Forms project through clicking File > New > Windows Application. Name the project KD Sample RDLC Reports
- Add new DataSet item to the Windows Forms project and name it AdventureWorks.xsd
- Drag TableAdapter from the toolbox to above AdventureWorks.xsd. Then TableAdapter Configuration Wizard will appear right now.
- Select New Connection and create a connection to the AdventureWorks SQL Server Database sample and go to next step
- When it comes to Enter a SQL Statement, copy following SQL statements to the textbox: SELECT ProductID, Name FROM Production.vProductAndDescription WHERE (CultureID = N'en'). Then click Finish
- Create a new custom Column to the DataTable through Add > Column and name the Column as KD Barcode
- Now we need to set the data type of the new Column KD Barcode as System.Byte[],Array of Byte. In the properties window. You may need to type the System.Byte[] manually if it is not listed in the dropdown list.
- Switch to forms1.cs, Add a new Repor item to the Windows application, and name the report item KDRdlcReport.rdlc
- In the Toolbar, drag a Table to the report from Report Item section
- Add three columns in AdventureWorks.xsd to the report table details section, that is, ProductID, Name and KD Barcode
- Drag an "Image" item to the last column KD Barcode
- Click that image and change its image properties:
- Customize image item property "MIMEType" as "image/jpeg"
- Customize image item property "Source" as "Database"
- Customize image item property "Value" as "=Fields!KD_Barcode.Value"
- Swich to Forms1.cs, drag and drop a ReportViewer control to the Windows Forms
- Choose your created report "KDRdlcReport.rdlc" and bind data collection
- Switch to "Solution Explorer" and add "KeepDynamic.Barcode.RdlcReport.dll" to your project reference
- Copy the following C# code into the method Form1_Load, and then run the project
private void Form1_Load(object sender, EventArgs e)
{
// load data to the data table
this.vProductAndDescriptionTableAdapter.Fill(this.AdventureWorks.vProductAndDescription);
// generate a linear barcode object
BarCode barcode = new BarCode();
// Adjust barcode type to Code 128
barcode.SymbologyType = SymbologyType.Code128;
// draw barcodes for each data row
foreach (AdventureWorks.vProductAndDescriptionRow row
in this.AdventureWorks.vProductAndDescription.Rows)
{
// set barcode encoding data value
barcode.CodeText = row.ProductID.ToString();
// Output barcode image in Jpeg image file
barcode.Format = System.Drawing.Imaging.ImageFormat.Jpeg;
row.Barcode = barcode.drawBarcodeAsBytes();
}
this.reportViewer1.RefreshReport();
}
Generate 1D/2D Barcodes in Local Reports Using RDLC Barcode Generator SDK
Barcode Generator SDK for RDLC reports is compatible with most common barcode symbology standards and supports more than seventy linear and two-dimensional barcode generation in local reports, such as:
- 2D Barcodes: Data Matrix for RDLC, PDF417 for RDLC and QR Code for RDLC.
- EAN/UPC Barcodes: ISSN for RDLC, ISBN for RDLC, UPC E for RDLC, UPC A for RDLC, EAN 8 for RDLC and EAN 13 for RDLC.
- Alphanumeric Barcodes: Code 93 for RDLC, Code 39 for RDLC and GS1-128 (UCC/EAN-128) for RDLC, Code 128 for RDLC.
- Numeric Barcodes: Code 11 for RDLC, Codabar for RDLC and MSI Plessey for RDLC.
- Postal Barcodes: Intelligent Mail Barcode for RDLC, RM4SCC for RDLC, USPS POSTNET for RDLC, USPS PLANET for RDLC,Identcode for RDLC and Leitcode for RDLC.
- Code 2 of 5 based Barcodes: Standard 2 of 5 for RDLC, Interleaved 2 of 5 for RDLC and ITF14 for RDLC.