Display Barcodes on Dataset Based Reports


Using datasets in reports is very common when programming with SQL Server Reporting Services. We provide a SQL query to populate the records in a dataset and use it as the data source for the report. Columns are bound to the fields in the dataset to automatically display the correct value of the record.

In this article, we use a simple table with three columns for the report. Below are the details of the table:

Table Name: Product

Column NamePurpose
IDAuto number. Used as primary key
ProductNameStore the product name.
ProductSerialStore the serial number. Display barcode for this value
The report will contain 4 columns. 3 columns displays the values from the table. The 4th column contains the barcode control. The barcode control uses the value of the “ProductSerial” column as codetext, for each of the rows.

Building the Report

Create a New Report

  1. Open Visual Studio.

  2. Create a new Report Server project.

  3. Add a new report.

  4. Choose the Report Wizard for creating the report.

  5. Choose the data source as shown in the figure below.

    Selecting the data source


  1. Click on Edit to create the connection string.

  2. Choose the database server and database as shown below.

    Selecting the databasde server and database


  1. Make sure that the connection string is valid by clicking Test Connection. If the connection works, you’ll see the message “test connection succeeded”.

  2. Click OK.

    The query designer


  1. Select all the columns from the Product table. Make sure that the query is valid by executing it in the query designer window; it should show some records from the table.

  2. Choose the Tabular option in the report type screen.

  3. Click Next.

  4. Add all the fields in the Detail category.

    Designing the table


  1. Click Next and call the report “Products List”.
  2. Click Finish to create the report.

The report should now be created. It show all the 3 columns from the “Product” table. Below is a preview of the report, as shown in the preview tab in Visual Studio.

A report preview


Add Barcode column

To display the barcode, add a new column.

  1. Open the report in design view.
  2. Right-click the Product Serial column and select Insert column and then Right. A new column is added.
  3. Name the column Barcode.
  4. Open the toolbox in Visual Studio and drag the Aspose.BarCode for Reporting Services control to the newly created column.

The report now looks like the one below.

Barcode column added to the report


Setting Symbology Type and Codetext

Now set the codetext and symbology type in the barcode control.

Set Symbology
  1. Right-click the barcode control and choose properties. The barcode designer window opens.

  2. Choose the desired barcode symbology from the list. In this example, we’ve selected Datamatrix.

    Setting the barcode symbology


Set Codetext

As you can see the code text has a default value of “12345678”. We need to change it to set the product serial number to be used as codetext.

  1. Click the fx (Expression) button next to the code text. The Expression window opens.

  2. Select Fields from the Category and select ProductSerial from the Values list. The Expression field should read =Fields!ProductSerial.Value.

    Defining the codetext


  1. Click OK. This sets the value of the ProductSerial column as the barcode codetext.

A preview of the report should now look like the one below.

The report preview, showing a barcode with the correct codetext


The barcode control picks the corresponding serial number for each product for the codetext.

Deploy the Report

You can also test the report by deploying it to SQL Server Reporting Services.

Below is a screenshot of the report when opened in Internet Explorer after deployment.

The final report



The barcode control for Reporting Services provides a custom properties window for designing the barcode. It also provides a way to give any expression (fx) for the codetext value. It can be a constant string or value of a dataset column. This article was about specifying the serial number column of a table as the codetext, which was very easily done using the barcode control.

Reference URLs