VB.NET Tutorial : using Crystal Report to Print Barcode Product label load from MySQL Database and ODBC connection in vb.net
VB.NET Tutorials : How to make simple Barcode Generator create in VB.NET and Print Barcode Product label using Crystal Report? This simple application will allow you to print Barcode product Labels using Report management (Crystal Report), You can set the number of the barcode where you want to print out and or you can do for all Barcode labels product just one click.
Please Read :
To create Barcode Generator, you must download and Install "IDAutomationHC39M" Font into your computer, download from this link https://www.dropbox.com/s/71ttbh2hhwu79ud/IDAutomationHC39M.ttf?dl=0
On the Step 3 (Figure 3), i think you must watch the video tutorials above.
We will create source code to show the Barcode Product from database into Crystal Report Viewer.
Note : Please watch full video tutorial above
Download Full Source Code
Download Example Databases
Please Read :
To create Barcode Generator, you must download and Install "IDAutomationHC39M" Font into your computer, download from this link https://www.dropbox.com/s/71ttbh2hhwu79ud/IDAutomationHC39M.ttf?dl=0
Create Project (Barcode Generator)
Open your visual studio and create new project. On your new project, please add new Item, we will create new report and load all Barcode labels to this report. Right Click on your project > Add > Add New Item >Figure 1- For more detail, please see the video tutorial at the end of this sessions |
Figure 2- For more detail, please see the video tutorial at the end of this sessions |
Figure 3- For more detail, please see the video tutorial at the end of this sessions |
Create New Form (Form1.Vb)
After create the Barcode Report has done, please back to the Form1.Vb, and Add Button Control, TextBox Control and Crystal Report Ciewer COntrol, just design it look like this images :We will create source code to show the Barcode Product from database into Crystal Report Viewer.
Source Code Barcode Generator (Form1.Vb)
Imports System.Data.Odbc ' im using ODBC connection to database
Imports CrystalDecisions.CrystalReports.Engine ' import cr engine
Public Class Form1
Dim connection As OdbcConnection
Dim cR As New ReportDocument
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cR.Load("c:\users\b0x\documents\visual studio 2015\Projects\BarcodeGenerator\BarcodeGenerator\Barcode.rpt")
End Sub
' we will create a connection to database (MySQL Database)
' im using ODBC connection
' you can use OleDB, ADO.NET, etc
Sub openConnection()
Try
connection = New OdbcConnection("DSN=db_penjualan;MultipleActiveResultSets=True")
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Catch ex As Exception
MsgBox("Connection failed" + ex.ToString)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
openConnection()
Dim sql As String = "SELECT * FROM as_products WHERE productBarcode='" & TextBox1.Text & "'"
For i As Integer = 1 To Integer.Parse(TextBox2.Text) - 1
sql = sql + "UNION ALL SELECT * FROM as_products WHERE productBarcode='" & TextBox1.Text & "'"
Next
Dim da As New OdbcDataAdapter(sql, connection) ' we will use dataadapter and dataset
Dim ds As New DataSet
da.Fill(ds, "as_products")
cR.SetDataSource(ds)
CrystalReportViewer1.ReportSource = cR
da.Dispose()
connection.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
openConnection()
Dim sql As String = "SELECT * FROM as_products"
Dim da As New OdbcDataAdapter(sql, connection) ' we will use dataadapter and dataset
Dim ds As New DataSet
da.Fill(ds, "as_products")
cR.SetDataSource(ds)
CrystalReportViewer1.ReportSource = cR
da.Dispose()
connection.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start("www.hc-kr.com")
End Sub
End Class
Note : Please watch full video tutorial above
Video Tutorial How to Create Barcode Generator
Download Full Source Code
Download Example Databases
COMMENTS