How to Display BarCodes in Report Header

Skip to end of metadata
Go to start of metadata
This tu torial covers how you can display BarCodes in Report header.
In Visual Studio, you cannot use a custom control in headers or footers. Since, Aspose.BarCode for Reporting Services is a control; you cannot just drag and drop the control to the header for displaying the barcode. But, the good news is that you can use images in report header and footer. In this tutorial, we will show how you can use image control to render BarCode image using Aspose.BarCode for Reporting Services.
Solution

Create a Report Server project in Visual Studio 2005.

Add a new “Shared Data Source”. In this example, we will use “AdventureWorks” database.

Add a new blank report to the project. Create a new “DataSet” for the report. Give the following SQL query in the “Query String” text area .

Select ProductID, Name, ProductNumber From Product


Click on “OK” button to save this dataset.

Now, we will add an image control to the report header. To view the header, switch to “Layout” view of the report and from the menu, select “Report” “Page Header”. From the Visual Studio toolbox, drag an Image control to the header. Select “Database” as the “Image Source”.


Press “Next” to go on next screen. In DataSet dropdown, select the dataset that you just created for the report. Select “ProductNumber” for the “Image field”. We will use this ProductNumber column as a CodeText to generate the BarCode. In MIME type, select “image/bmp”.


Press “Finish” to end the “image add” wizard.

After this, add a reference to the Aspose.BarCode .ReportingServices.dll. Select “Report” “Report Properties” and click on the “References” tab. Browse the Aspose.BarCode.ReportingServices.dll and add it to the references. A reference to System.Drawing dll is also required, which can be found in the .NET tab. In “Classes” tab, add the description for the class as follows:

Class Name: Aspose.BarCode.ReportingServices.BarCodeBuilder

Instance Name: objBarCode


Now, click on the “Code” tab and add the following code.

Public Function GetBarCodeImage(ByVal codetext As String) As Byte()
	objBarcode.CodeText = codetext
	objBarcode.SymbologyType = Aspose.BarCode.ReportingServices.Symbology.Code39Standard
	'Generate the barcode image
Dim ms As New System.IO.MemoryStream
objBarcode.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp)
Return ms.GetBuffer()
End Function
 




Click on “OK” to save the reference, class details and the code.

So far, we have added the image and th e code to generate the BarCode.

Click on “View” “DataSets” and drag the “ProductNumber” and “Name” columns to the report body. Also add 2 textboxes to the body for the purpose of adding labels. The Report layout should look as follows:


Now right click on the image control and select “Properties”. Set the value as “ =Code.GetBarCodeImage(ReportItems!ProductNumber.Value)


Save all the files and click on “Preview” tab. You should see the similar output as below:


If you cannot see the BarCode, please click on the “Print Layout” icon on the toolbar. This will show the report with the header and footer.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.