Vbnet+billing+software+source+code
Are you integrating specialized like barcode scanners or thermal receipt printers?
Downloading a project and trying to make it work is just the first step. To truly learn and adapt it, follow this systematic approach:
Manages information for tracking sales and purchasing.
: Secures access through user roles (Admin, Cashier). vbnet+billing+software+source+code
Create an MS Access database named BillingDB.accdb [1]. Create the following two core tables to handle inventory management and invoicing. Table 1: Products This table stores the store's current inventory [1]. Field Name Description ProductID AutoNumber Primary Key ProductName Short Text Name of the item Price Unit price Stock Available quantity Table 2: InvoiceDetails
: Set the txtProductCode control to auto-focus after every transaction. Barcode scanners automatically append a carriage return ( Enter key), which natively activates the transaction processing routine within txtProductCode_KeyDown .
Let’s break it down.
Imports System.Data.SQLite Public Class frmBilling Private Sub frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load DbManager.InitializeDatabase() InitializeGrid() LoadProducts() End Sub Private Sub InitializeGrid() With dgvInvoiceItems .Columns.Clear() .Columns.Add("ProdID", "ID") .Columns.Add("ProdName", "Product Name") .Columns.Add("Price", "Price") .Columns.Add("Qty", "Quantity") .Columns.Add("SubTotal", "Subtotal") .Columns("ProdID").Width = 50 .Columns("ProdName").Width = 200 End With End Sub Private Sub LoadProducts() Try Using conn As SQLiteConnection = DbManager.GetConnection() conn.Open() Dim query As String = "SELECT ProductID, ProductName, Price FROM Products" Using cmd As New SQLiteCommand(query, conn) Dim adapter As New SQLiteDataAdapter(cmd) Dim dt As New DataTable() adapter.Fill(dt) cmbProducts.DisplayMember = "ProductName" cmbProducts.ValueMember = "ProductID" cmbProducts.DataSource = dt End Using End Using Catch ex As Exception MessageBox.Show("Error loading products: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub ' Auto-populate price when product selection changes Private Sub cmbProducts_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProducts.SelectedIndexChanged If cmbProducts.SelectedItem IsNot Nothing Then Dim drv As DataRowView = CType(cmbProducts.SelectedItem, DataRowView) txtPrice.Text = Convert.ToDecimal(drv("Price")).ToString("F2") End If End Sub ' Add Selected Item to DataGridView Private Sub btnAddToGrid_Click(sender As Object, e As EventArgs) Handles btnAddToGrid.Click Dim qty As Integer Dim price As Decimal If Not Integer.TryParse(txtQuantity.Text, qty) OrElse qty <= 0 Then MessageBox.Show("Please enter a valid quantity.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Decimal.TryParse(txtPrice.Text, price) Dim subTotal As Decimal = price * qty ' Append line item to UI Grid dgvInvoiceItems.Rows.Add(cmbProducts.SelectedValue, cmbProducts.Text, price, qty, subTotal) CalculateGrandTotal() ClearProductInputs() End Sub Private Sub CalculateGrandTotal() Dim grandTotal As Decimal = 0 For Each row As DataGridViewRow In dgvInvoiceItems.Rows If Not row.IsNewRow Then grandTotal += Convert.ToDecimal(row.Cells("SubTotal").Value) End If Next lblGrandTotal.Text = grandTotal.ToString("C") lblGrandTotal.Tag = grandTotal ' Store clean numeric value End Sub Private Sub ClearProductInputs() txtQuantity.Clear() cmbProducts.Focus() End Sub ' Save Invoice Transaction to Database Private Sub btnSavePrint_Click(sender As Object, e As EventArgs) Handles btnSavePrint.Click If dgvInvoiceItems.Rows.Count = 0 Then MessageBox.Show("The invoice is empty.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Using conn As SQLiteConnection = DbManager.GetConnection() conn.Open() Using transaction = conn.BeginTransaction() Try ' 1. Insert Master Invoice Header Dim insertInvoice As String = "INSERT INTO Invoices (InvoiceDate, CustomerName, GrandTotal) VALUES (@Date, @Cust, @Total); SELECT last_insert_rowid();" Dim invoiceId As Integer Using cmd As New SQLiteCommand(insertInvoice, conn, transaction) cmd.Parameters.AddWithValue("@Date", DateTime.Now) cmd.Parameters.AddWithValue("@Cust", If(String.IsNullOrWhiteSpace(txtCustomerName.Text), "Walk-in Customer", txtCustomerName.Text)) cmd.Parameters.AddWithValue("@Total", Convert.ToDecimal(lblGrandTotal.Tag)) invoiceId = Convert.ToInt32(cmd.ExecuteScalar()) End Using ' 2. Insert Invoice Line Items & Update Stock For Each row As DataGridViewRow In dgvInvoiceItems.Rows If Not row.IsNewRow Then Dim prodId As Integer = Convert.ToInt32(row.Cells("ProdID").Value) Dim price As Decimal = Convert.ToDecimal(row.Cells("Price").Value) Dim qty As Integer = Convert.ToInt32(row.Cells("Qty").Value) Dim subtotal As Decimal = Convert.ToDecimal(row.Cells("SubTotal").Value) ' Insert Detail Record Dim insertDetail As String = "INSERT INTO InvoiceDetails (InvoiceID, ProductID, Quantity, UnitPrice, SubTotal) VALUES (@InvID, @ProdID, @Qty, @Price, @Sub);" Using cmdDetail As New SQLiteCommand(insertDetail, conn, transaction) cmdDetail.Parameters.AddWithValue("@InvID", invoiceId) cmdDetail.Parameters.AddWithValue("@ProdID", prodId) cmdDetail.Parameters.AddWithValue("@Qty", qty) cmdDetail.Parameters.AddWithValue("@Price", price) cmdDetail.Parameters.AddWithValue("@Sub", subtotal) cmdDetail.ExecuteNonQuery() End Using ' Deduct inventory stock Dim updateStock As String = "UPDATE Products SET StockQuantity = StockQuantity - @Qty WHERE ProductID = @ProdID" Using cmdStock As New SQLiteCommand(updateStock, conn, transaction) cmdStock.Parameters.AddWithValue("@Qty", qty) cmdStock.Parameters.AddWithValue("@ProdID", prodId) cmdStock.ExecuteNonQuery() End Using End If Next transaction.Commit() MessageBox.Show("Invoice #" & invoiceId & " saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) ResetForm() Catch ex As Exception transaction.Rollback() MessageBox.Show("Transaction failed: " & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Using End Using End Sub Private Sub ResetForm() txtCustomerName.Clear() dgvInvoiceItems.Rows.Clear() lblGrandTotal.Text = "$0.00" lblGrandTotal.Tag = 0.0 LoadProducts() End Sub End Class Use code with caution. 📈 Enterprise Production Extensions
Functionality to calculate total, apply discounts, and generate taxes based on the items in the data grid. Essential Features to Implement
This centralized module safely opens connection pools to your database backend. Swap out the connection string based on your local SQL Server instance. Are you integrating specialized like barcode scanners or
VB.NET Billing Software Source Code: A Comprehensive Guide to Building Efficient POS Systems
Ensure your database structure is normalized to reduce data redundancy.
In the modern business landscape, efficiency is paramount. Small to medium-sized enterprises (SMEs) often require tailored solutions to manage invoicing, inventory, and customer data, rather than adopting expensive, generic SaaS platforms. Developing custom billing software using remains a popular choice due to its rapid application development (RAD) capabilities, ease of use, and deep integration with Windows-based environments. : Secures access through user roles (Admin, Cashier)
✅ – No internet needed. Great for small shops, warehouses, or rural businesses.
Seamless connectivity with Microsoft SQL Server, MySQL, and MS Access using ADO.NET.