CrystalReport1.vb
'------------------------------------------------------------------------------ ' <auto-generated> ' This code was generated by a tool. ' Runtime Version:4.0.30319.34014 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </auto-generated> '------------------------------------------------------------------------------ Option Strict Off Option Explicit On Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.ReportSource Imports CrystalDecisions.Shared Imports System Imports System.ComponentModel Public Class CrystalReport1 Inherits ReportClass Public Sub New() MyBase.New End Sub Public Overrides Property ResourceName() As String Get Return "CrystalReport1.rpt" End Get Set 'Do nothing End Set End Property Public Overrides Property NewGenerator() As Boolean Get Return true End Get Set 'Do nothing End Set End Property Public Overrides Property FullResourceName() As String Get Return "BarcodeInCrystalReports.CrystalReport1.rpt" End Get Set 'Do nothing End Set End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property Section1() As CrystalDecisions.CrystalReports.Engine.Section Get Return Me.ReportDefinition.Sections(0) End Get End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property Section2() As CrystalDecisions.CrystalReports.Engine.Section Get Return Me.ReportDefinition.Sections(1) End Get End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property Section3() As CrystalDecisions.CrystalReports.Engine.Section Get Return Me.ReportDefinition.Sections(2) End Get End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property Section4() As CrystalDecisions.CrystalReports.Engine.Section Get Return Me.ReportDefinition.Sections(3) End Get End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property Section5() As CrystalDecisions.CrystalReports.Engine.Section Get Return Me.ReportDefinition.Sections(4) End Get End Property End Class <System.Drawing.ToolboxBitmapAttribute(GetType(CrystalDecisions.[Shared].ExportOptions), "report.bmp")> _ Public Class CachedCrystalReport1 Inherits Component Implements ICachedReport Public Sub New() MyBase.New End Sub <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public Overridable Property IsCacheable() As Boolean Implements CrystalDecisions.ReportSource.ICachedReport.IsCacheable Get Return true End Get Set ' End Set End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public Overridable Property ShareDBLogonInfo() As Boolean Implements CrystalDecisions.ReportSource.ICachedReport.ShareDBLogonInfo Get Return false End Get Set ' End Set End Property <Browsable(false), _ DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _ Public Overridable Property CacheTimeOut() As System.TimeSpan Implements CrystalDecisions.ReportSource.ICachedReport.CacheTimeOut Get Return CachedReportConstants.DEFAULT_TIMEOUT End Get Set ' End Set End Property Public Overridable Function CreateReport() As CrystalDecisions.CrystalReports.Engine.ReportDocument Implements CrystalDecisions.ReportSource.ICachedReport.CreateReport Dim rpt As CrystalReport1 = New CrystalReport1() rpt.Site = Me.Site Return rpt End Function Public Overridable Function GetCustomizedCacheKey(ByVal request As RequestContext) As String Implements CrystalDecisions.ReportSource.ICachedReport.GetCustomizedCacheKey Dim key As [String] = Nothing '// The following is the code used to generate the default '// cache key for caching report jobs in the ASP.NET Cache. '// Feel free to modify this code to suit your needs. '// Returning key == null causes the default cache key to '// be generated. ' 'key = RequestContext.BuildCompleteCacheKey( ' request, ' null, // sReportFilename ' this.GetType(), ' this.ShareDBLogonInfo ); Return key End Function End Class
Form1.vb
Imports System.Data.OleDb Imports Bytescout.BarCode Public Class Form1 Private Sub CrystalReportViewer1_Load(sender As System.Object, e As System.EventArgs) Handles CrystalReportViewer1.Load Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=products.mdb") Dim dataAdapter As New OleDbDataAdapter("SELECT ID, ProductName, ProductDescription, ProductPrice FROM Products", connection) ' fill dataset Dim dataSet As New DataSet() dataAdapter.Fill(dataSet) connection.Close() 'add virtual column into the result table dataSet.Tables(0).Columns.Add(New DataColumn("BarcodeImage", GetType(System.Byte()))) ' create barcode object Dim barcode As New Barcode(SymbologyType.Code128) barcode.DrawCaption = False ' Fill BarcodeImage column with generated barcode image bytes For Each row As DataRow In dataSet.Tables(0).Rows 'set barcode value barcode.Value = Convert.ToString(row("ID")) ' retrieve generated image bytes Dim barcodeBytes As Byte() = barcode.GetImageBytesWMF() ' fill virtual column with generated image bytes row("BarcodeImage") = barcodeBytes Next ' set filled DataSet as report's data source CrystalReport11.SetDataSource(dataSet.Tables(0)) End Sub End Class
ProductsDataSet.xsd
<?xml version="1.0" encoding="utf-8"?> <xs:schema id="ProductsDataSet" targetNamespace="http://tempuri.org/ProductsDataSet.xsd" xmlns:mstns="http://tempuri.org/ProductsDataSet.xsd" xmlns="http://tempuri.org/ProductsDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:annotation> <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource"> <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource"> <Connections> <Connection AppSettingsObjectName="MySettings" AppSettingsPropertyName="productsConnectionString" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="productsConnectionString (MySettings)" PropertyReference="ApplicationSettings.CrystalReportsApplication2.My.MySettings.GlobalReference.Default.productsConnectionString" Provider="System.Data.OleDb" /> </Connections> <Tables> <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="ProductsTableAdapter" GeneratorDataComponentClassName="ProductsTableAdapter" Name="Products" UserDataComponentName="ProductsTableAdapter"> <MainSource> <DbSource ConnectionRef="productsConnectionString (MySettings)" DbObjectName="Products" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="true" UserGetMethodName="GetData" UserSourceName="Fill"> <DeleteCommand> <DbCommand CommandType="Text" ModifiedByUser="false"> <CommandText>DELETE FROM `Products` WHERE ((`ID` = ?) AND ((? = 1 AND `ProductName` IS NULL) OR (`ProductName` = ?)) AND ((? = 1 AND `ProductDescription` IS NULL) OR (`ProductDescription` = ?)) AND ((? = 1 AND `ProductPrice` IS NULL) OR (`ProductPrice` = ?)))</CommandText> <Parameters> <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="Original_ID" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ID" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductDescription" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductDescription" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductPrice" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductPrice" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="false" SourceVersion="Original" /> </Parameters> </DbCommand> </DeleteCommand> <InsertCommand> <DbCommand CommandType="Text" ModifiedByUser="false"> <CommandText>INSERT INTO `Products` (`ProductName`, `ProductDescription`, `ProductPrice`) VALUES (?, ?, ?)</CommandText> <Parameters> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="false" SourceVersion="Current" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductDescription" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="false" SourceVersion="Current" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductPrice" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="false" SourceVersion="Current" /> </Parameters> </DbCommand> </InsertCommand> <SelectCommand> <DbCommand CommandType="Text" ModifiedByUser="false"> <CommandText>SELECT ID, ProductName, ProductDescription, ProductPrice FROM Products</CommandText> <Parameters /> </DbCommand> </SelectCommand> <UpdateCommand> <DbCommand CommandType="Text" ModifiedByUser="false"> <CommandText>UPDATE `Products` SET `ProductName` = ?, `ProductDescription` = ?, `ProductPrice` = ? WHERE ((`ID` = ?) AND ((? = 1 AND `ProductName` IS NULL) OR (`ProductName` = ?)) AND ((? = 1 AND `ProductDescription` IS NULL) OR (`ProductDescription` = ?)) AND ((? = 1 AND `ProductPrice` IS NULL) OR (`ProductPrice` = ?)))</CommandText> <Parameters> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="false" SourceVersion="Current" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductDescription" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="false" SourceVersion="Current" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProductPrice" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="false" SourceVersion="Current" /> <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="Original_ID" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ID" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductName" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductDescription" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductDescription" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductDescription" SourceColumnNullMapping="false" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProductPrice" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="true" SourceVersion="Original" /> <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProductPrice" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProductPrice" SourceColumnNullMapping="false" SourceVersion="Original" /> </Parameters> </DbCommand> </UpdateCommand> </DbSource> </MainSource> <Mappings> <Mapping SourceColumn="ID" DataSetColumn="ID" /> <Mapping SourceColumn="ProductName" DataSetColumn="ProductName" /> <Mapping SourceColumn="ProductDescription" DataSetColumn="ProductDescription" /> <Mapping SourceColumn="ProductPrice" DataSetColumn="ProductPrice" /> </Mappings> <Sources /> </TableAdapter> </Tables> <Sources /> </DataSource> </xs:appinfo> </xs:annotation> <xs:element name="ProductsDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:EnableTableAdapterManager="True" msprop:Generator_DataSetName="ProductsDataSet" msprop:Generator_UserDSName="ProductsDataSet"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="Products" msprop:Generator_TableClassName="ProductsDataTable" msprop:Generator_TableVarName="tableProducts" msprop:Generator_RowChangedName="ProductsRowChanged" msprop:Generator_TablePropName="Products" msprop:Generator_RowDeletingName="ProductsRowDeleting" msprop:Generator_RowChangingName="ProductsRowChanging" msprop:Generator_RowEvHandlerName="ProductsRowChangeEventHandler" msprop:Generator_RowDeletedName="ProductsRowDeleted" msprop:Generator_RowClassName="ProductsRow" msprop:Generator_UserTableName="Products" msprop:Generator_RowEvArgName="ProductsRowChangeEvent"> <xs:complexType> <xs:sequence> <xs:element name="ID" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1" msdata:AutoIncrementStep="-1" msprop:Generator_ColumnVarNameInTable="columnID" msprop:Generator_ColumnPropNameInRow="ID" msprop:Generator_ColumnPropNameInTable="IDColumn" msprop:Generator_UserColumnName="ID" type="xs:int" /> <xs:element name="ProductName" msprop:Generator_ColumnVarNameInTable="columnProductName" msprop:Generator_ColumnPropNameInRow="ProductName" msprop:Generator_ColumnPropNameInTable="ProductNameColumn" msprop:Generator_UserColumnName="ProductName" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="255" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="ProductDescription" msprop:Generator_ColumnVarNameInTable="columnProductDescription" msprop:Generator_ColumnPropNameInRow="ProductDescription" msprop:Generator_ColumnPropNameInTable="ProductDescriptionColumn" msprop:Generator_UserColumnName="ProductDescription" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="255" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="ProductPrice" msprop:Generator_ColumnVarNameInTable="columnProductPrice" msprop:Generator_ColumnPropNameInRow="ProductPrice" msprop:Generator_ColumnPropNameInTable="ProductPriceColumn" msprop:Generator_UserColumnName="ProductPrice" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="255" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="BarcodeImage" msprop:Generator_ColumnVarNameInTable="columnBarcodeImage" msprop:Generator_ColumnPropNameInRow="BarcodeImage" msprop:Generator_ColumnPropNameInTable="BarcodeImageColumn" msprop:Generator_UserColumnName="BarcodeImage" type="xs:base64Binary" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:unique name="Constraint1" msdata:PrimaryKey="true"> <xs:selector xpath=".//mstns:Products" /> <xs:field xpath="mstns:ID" /> </xs:unique> </xs:element> </xs:schema>