Code 128 Barcodes in SQL Server Reporting Services (SSRS)

How to create barcodes in SSRS

  • BarCodeWiz Code 128 Fonts may be used to create barcodes in SSRS. Follow the steps below to add barcodes to your own report.
Code 128 barcodes in SSRS - preview

Step 1. Create a new report

  • Click on File > New > Blank Report
Create a new report SSRS

Step 2. Add Code to the Report

  • Right click in the report background area and click Report Properties...
Add Code 128 source code to the report
  • In the Report Properties window, select the Code section.
  • The Custom code window is empty at this time. Let's copy/paste Code 128 barcode functions here.
Open window
  • Locate the text file containing the code. The default location of the text file is:
    Documents\BarCodeWiz Examples\Code 128 Barcode Fonts\Report Builder\code.txt
Locate text file with source code
  • Copy the contents of the file into the Custom Code window
Copy contents of the file

Step 3. Add a Reference to System.Drawing.dll

  • Click on References > Add
Add a new Reference
  • Click on the Ellipsis button (...)
Ellipsis button
  • Locate System.Drawing.dll. One possible location is under:
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\
  • Close the Properties window.
Locate the Reference

Step 4. Connect your Data Source

  • Connect to a data source. We are using an Access database in this example. You may find the database under:
    Documents\BarCodeWiz Examples\Code 128 Barcode Fonts\barcodewiz.mdb
  • The data structure is as below:
Connect to Data Source

Step 5. Insert a Table into the report

  • Click on Insert > Table > Insert Table
Insert a new table into the report

Step 6. Add an Image for our barcode

  • Click on Insert > Image
Add an image for barcode
  • Place the image in the table
Place barcode image in table

Step 7. Edit Image Properties

  • Select Database as the image source.
  • Select image/png as the MIME type.
  • Click on the second Fx button to open the Expression window.
Edit image properties
  • Set the value for the expression:
    =Code.Code128B(Fields!item_barcode.Value,1,True)
  • Replace item_barcode with the name of the field from your dataset.
  • See here for function descriptions
Set the Code 128 code

Step 8. (Optional) Add other fields to the report

Add more data fields

Ready!

  • Preview the generated report.
You're finished

Code 128 Fonts Functions in SSRS

Code128A(barcode as String, height as Integer, showText as Boolean)

  • Code128A() Encodes data using Code 128 Subset A only. It supports numbers, upper case letters, control characters (such as tab or new-line), space, and the following: !"#$%&'()*+,-./:;<=>?@[\]^_
  • This function uses one of the following fonts:
    BCW_Code128A_1 through BCW_Code128A_6 (shows human-readable text under barcode)
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • The function parameters are as folows:
    barcode : String value with the barcode data to encode.
    height: Integer value indicating which version of the font height should be selected. Valid values are from 1 to 6.
    showText: Boolean value indicating whether or not to show the human readable text below barcode image.

Code128B(barcode as String, height as Integer, showText as Boolean)

  • Code128B() Encodes data using Code 128 Subset B only. It supports numbers, upper and lower-case letters, space, and the following characters: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
  • This function uses one of the following fonts:
    BCW_Code128B_1 through BCW_Code128B_6 (shows human-readable text under barcode)
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • The function parameters are as folows:
    barcode : String value with the barcode data to encode.
    height: Integer value indicating which version of the font height should be selected. Valid values are from 1 to 6.
    showText: Boolean value indicating whether or not to show the human readable text below barcode image.

Code128C(barcode as String, height as Integer, showText as Boolean)

  • Code128C() Encodes data using Code 128 Subset C. It supports numbers only and must contain an even number of digits.
  • The digits are encoded in pairs of two, resulting in a barcode about half as wide as subset A or B.
  • This function uses one of the following fonts:
    BCW_Code128C_1 through BCW_Code128C_6 (shows human-readable text under barcode)
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • The function parameters are as folows:
    barcode : String value with the barcode data to encode.
    height: Integer value indicating which version of the font height should be selected. Valid values are from 1 to 6.
    showText: Boolean value indicating whether or not to show the human readable text below barcode image.