Neodynamic Barcode Professional 3.0 (or greater) for ASP.NET (WebControl)
Microsoft .NET Framework 2.0 (or greater)
Microsoft Visual Studio 2005
Microsoft SQL Server 2000 (or greater) with Northwind Database sample installed
Crystal Report for Visual Studio .NET 2005
In the following Step-By-Step Guide we're going to create a Crystal Report which features barcoding capabilities by using Barcode Professional for ASP.NET and using as data source for the report a SQL Stored Procedure.
Follow these steps:
ALTER PROCEDURE dbo.GetCustomers AS
SELECT CustomerID, CompanyName, City, Country
FROM Customers
RETURN
In order to support barcoding capabilities in Crystal Reports by using a SQL Stored Procedure as the data source, we'll need to modify the involved SP so it returns an additional column of type SQL Image. The purpose of such SQL Image field will be to hold the barcode image generated by Barcode Professional for each customer in the result set.
ALTER PROCEDURE dbo.GetCustomers AS
/*
Local variable to initialize Barcode field
*/
DECLARE @barcodeImage AS BINARY
SET @barcodeImage = NULL
/*
Create a SQL Temp Table with the same structure as Customers Table
and adding an additional field of type Image for barcoding
*/
CREATE TABLE #CustomerTempTable
(
CustomerID NCHAR(5),
CompanyName NVARCHAR(40),
City NVARCHAR(15),
Country NVARCHAR(15),
Barcode IMAGE
)
/*
Populate the temp table
*/
INSERT INTO #CustomerTempTable
SELECT CustomerID, CompanyName, City, Country, @barcodeImage
FROM Customers
/*
Return result set with barcode column
*/
SELECT * FROM #CustomerTempTable
/*
Delete temp table
*/
DROP TABLE #CustomerTempTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Getting Customers from DB
Dim cnn As New System.Data.SqlClient.SqlConnection("Data Source=neo3\sql2000;Initial Catalog=Northwind;Integrated Security=True")
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = cnn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "GetCustomers"
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd)
Dim dsCustomers As New DataSet()
da.Fill(dsCustomers)
'Create an instance of Barcode Professional
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code39
bcp.Extended = True
bcp.AddChecksum = False
bcp.BarHeight = 0.4F
bcp.QuietZoneWidth = 0
Dim row As DataRow
'Update Customers DataTable with barcode image
For Each row In dsCustomers.Tables(0).Rows
'Set the value to encode
bcp.Code = row("CustomerID").ToString()
'Generate the barcode image and store it into the Barcode Column
row("Barcode") = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
Next
'Create a report object
'and set its data source with the DataSet
Dim report As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim rptFile As String = Server.MapPath("CrystalReportBarcode.rpt")
report.Load(rptFile)
report.SetDataSource(dsCustomers.Tables(0))
Me.CrystalReportViewer1.ReportSource = report
End Sub
protected void Page_Load(object sender, EventArgs e)
{
//Getting Customers from DB
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(@"Data Source=neo3\sql2000;Initial Catalog=Northwind;Integrated Security=True");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetCustomers";
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet dsCustomers = new DataSet();
da.Fill(dsCustomers);
//Create an instance of Barcode Professional
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code39;
bcp.Extended = true;
bcp.AddChecksum = false;
bcp.BarHeight = 0.4f;
bcp.QuietZoneWidth = 0;
//Update Customers DataTable with barcode image
foreach (DataRow row in dsCustomers.Tables[0].Rows)
{
//Set the value to encode
bcp.Code = row["CustomerID"].ToString();
//Generate the barcode image and store it into the Barcode Column
row["Barcode"] = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
}
//Create a report object
//and set its data source with the DataSet
CrystalDecisions.CrystalReports.Engine.ReportDocument report;
report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string rptFile = Server.MapPath("CrystalReportBarcode.rpt");
report.Load(rptFile);
report.SetDataSource(dsCustomers.Tables[0]);
this.CrystalReportViewer1.ReportSource = report;
}
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.