Code: Vb.net Billing Software Source

Most VB.NET billing source code examples use either Microsoft SQL Server Express (free, robust) or MS Access (portable, simple). Below is a normalized schema for a professional system.

Public Class frmProducts
    Private Sub frmProducts_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadProducts()
    End Sub
Private Sub LoadProducts()
    Try
        Dim dt As DataTable = Product.GetAllProducts()
        dgvProducts.DataSource = dt
        dgvProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    Catch ex As Exception
        MessageBox.Show("Error loading products: " & ex.Message)
    End Try
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    If ValidateFields() Then
        Dim product As New Product()
        product.ProductCode = txtProductCode.Text
        product.ProductName = txtProductName.Text
        product.Category = txtCategory.Text
        product.UnitPrice = Decimal.Parse(txtPrice.Text)
        product.StockQuantity = Integer.Parse(txtStock.Text)
        product.GSTPercentage = Decimal.Parse(txtGST.Text)
If product.AddProduct() Then
            MessageBox.Show("Product added successfully!")
            ClearFields()
            LoadProducts()
        End If
    End If
End Sub
Private Function ValidateFields() As Boolean
    If String.IsNullOrWhiteSpace(txtProductCode.Text) Then
        MessageBox.Show("Product code is required")
        Return False
    End If
    If String.IsNullOrWhiteSpace(txtProductName.Text) Then
        MessageBox.Show("Product name is required")
        Return False
    End If
    If Not Decimal.TryParse(txtPrice.Text, Nothing) Then
        MessageBox.Show("Invalid price")
        Return False
    End If
    Return True
End Function
Private Sub ClearFields()
    txtProductCode.Clear()
    txtProductName.Clear()
    txtCategory.Clear()
    txtPrice.Clear()
    txtStock.Clear()
    txtGST.Clear()
End Sub

End Class

Imports System.Data.SqlClient

Public Class frmBilling Private dtCart As New DataTable() Private currentInvoiceNumber As String = ""

Private Sub frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    InitializeCartTable()
    GenerateInvoiceNumber()
    LoadProducts()
    LoadCustomers()
End Sub
Private Sub InitializeCartTable()
    dtCart.Columns.Add("ProductID", GetType(Integer))
    dtCart.Columns.Add("ProductCode", GetType(String))
    dtCart.Columns.Add("ProductName", GetType(String))
    dtCart.Columns.Add("Quantity", GetType(Integer))
    dtCart.Columns.Add("UnitPrice", GetType(Decimal))
    dtCart.Columns.Add("GST", GetType(Decimal))
    dtCart.Columns.Add("Total", GetType(Decimal))
    dgvCart.DataSource = dtCart
    FormatDataGridView()
End Sub
Private Sub FormatDataGridView()
    dgvCart.Columns("ProductID").Visible = False
    dgvCart.Columns("ProductCode").HeaderText = "Product Code"
    dgvCart.Columns("ProductName").HeaderText = "Product Name"
    dgvCart.Columns("Quantity").HeaderText = "Qty"
    dgvCart.Columns("UnitPrice").HeaderText = "Unit Price"
    dgvCart.Columns("GST").HeaderText = "GST %"
    dgvCart.Columns("Total").HeaderText = "Total"
    dgvCart.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
End Sub
Private Sub GenerateInvoiceNumber()
    currentInvoiceNumber = "INV-" & DateTime.Now.ToString("yyyyMMdd") & "-" & DateTime.Now.ToString("HHmmss")
    txtInvoiceNo.Text = currentInvoiceNumber
End Sub
Private Sub LoadProducts()
    Try
        Dim dt As DataTable = Product.GetAllProducts()
        cmbProductName.DataSource = dt
        cmbProductName.DisplayMember = "ProductName"
        cmbProductName.ValueMember = "ProductID"
        cmbProductName.SelectedIndex = -1
    Catch ex As Exception
        MessageBox.Show("Error loading products: " & ex.Message)
    End Try
End Sub
Private Sub LoadCustomers()
    Try
        Dim query As String = "SELECT CustomerID, CustomerName FROM Customers"
        DBConnection.OpenConnection()
        Dim adapter As New SqlDataAdapter(query, DBConnection.conn)
        Dim dt As New DataTable()
        adapter.Fill(dt)
        cmbCustomer.DataSource = dt
        cmbCustomer.DisplayMember = "CustomerName"
        cmbCustomer.ValueMember = "CustomerID"
        DBConnection.CloseConnection()
    Catch ex As Exception
        MessageBox.Show("Error loading customers: " & ex.Message)
    End Try
End Sub
Private Sub cmbProductName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProductName.SelectedIndexChanged
    If cmbProductName.SelectedValue IsNot Nothing Then
        Try
            Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue)
            Dim query As String = "SELECT ProductCode, UnitPrice, GSTPercentage FROM Products WHERE ProductID = @ProductID"
            DBConnection.OpenConnection()
            Using cmd As New SqlCommand(query, DBConnection.conn)
                cmd.Parameters.AddWithValue("@ProductID", productID)
                Using reader As SqlDataReader = cmd.ExecuteReader()
                    If reader.Read() Then
                        txtProductCode.Text = reader("ProductCode").ToString()
                        txtPrice.Text = reader("UnitPrice").ToString()
                        txtGST.Text = reader("GSTPercentage").ToString()
                        txtQuantity.Text = "1"
                        CalculateTotal()
                    End If
                End Using
            End Using
            DBConnection.CloseConnection()
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)
        End Try
    End If
End Sub
Private Sub CalculateTotal()
    If txtQuantity.Text <> "" And txtPrice.Text <> "" Then
        Dim quantity As Integer = Integer.Parse(txtQuantity.Text)
        Dim price As Decimal = Decimal.Parse(txtPrice.Text)
        Dim gst As Decimal = Decimal.Parse(txtGST.Text)
        Dim subtotal As Decimal = quantity * price
        Dim gstAmount As Decimal = subtotal * (gst / 100)
        Dim total As Decimal = subtotal + gstAmount
        txtSubtotal.Text = subtotal.ToString("N2")
        txtGSTAmount.Text = gstAmount.ToString("N2")
        txtTotal.Text = total.ToString("N2")
    End If
End Sub
Private Sub txtQuantity_TextChanged(sender As Object, e As EventArgs) Handles txtQuantity.TextChanged
    CalculateTotal()
End Sub
Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click
    If cmbProductName.SelectedValue Is Nothing Then
        MessageBox.Show("Please select a product")
        Return
    End If
Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue)
    Dim productCode As String = txtProductCode.Text
    Dim productName As String = cmbProductName.Text
    Dim quantity As Integer = Integer.Parse(txtQuantity.Text)
    Dim unitPrice As Decimal = Decimal.Parse(txtPrice.Text)
    Dim gst As Decimal = Decimal.Parse(txtGST.Text)
    Dim total As Decimal = Decimal.Parse(txtTotal.Text)
' Check if product already in cart
    Dim existingRow As DataRow() = dtCart.Select("ProductID = " & productID)
    If existingRow.Length > 0 Then
        existingRow(0)("Quantity") = CInt(existingRow(0)("Quantity")) + quantity
        existingRow(0)("Total") = CDec(existingRow(0)("Quantity")) * unitPrice
    Else
        dtCart.Rows.Add(productID, productCode, productName, quantity, unitPrice, gst, total)
    End If
UpdateGrandTotal()
    ClearProductFields()
End Sub
Private Sub UpdateGrandTotal()
    Dim grandTotal As Decimal = 0
    For Each row As DataRow In dtCart.Rows
        grandTotal += CDec(row("Total"))
    Next
    lblGrandTotal.Text = "Grand Total: ₹" & grandTotal.ToString("N2")
End Sub
Private Sub ClearProductFields()
    cmbProductName.SelectedIndex = -1
    txtProductCode.Clear()
    txtPrice.Clear()
    txtGST.Clear()
    txtQuantity.Clear()
    txtSubtotal.Clear()
    txtGSTAmount.Clear()
    txtTotal.Clear()
    txtQuantity.Text = "1"
End Sub
Private Sub btnRemoveFromCart_Click(sender As Object, e As EventArgs) Handles btnRemoveFromCart.Click
    If dgvCart.CurrentRow IsNot Nothing Then
        dtCart.Rows.RemoveAt(dgvCart.CurrentRow.Index)
        UpdateGrandTotal()
    End If
End Sub
Private Sub btnSaveInvoice_Click(sender As Object, e As EventArgs) Handles btnSaveInvoice.Click
    If dtCart.Rows.Count = 0 Then
        MessageBox.Show("Cart is empty!")
        Return
    End If
If cmbCustomer.SelectedValue Is Nothing Then
        MessageBox.Show("Please select a customer")
        Return
    End If
Try
        DBConnection.OpenConnection()
        Dim transaction As SqlTransaction = DBConnection.conn.BeginTransaction()
Try
            ' Calculate totals
            Dim subtotal As Decimal = 0
            Dim totalGST As Decimal = 0
            For Each row As DataRow In dtCart.Rows
                subtotal += CDec(row("Total"))
            Next
Dim totalAmount As Decimal = subtotal
' Insert Invoice
            Dim invoiceQuery As String = "INSERT INTO Invoices (InvoiceNumber, CustomerID, InvoiceDate, SubTotal, GSTAmount, TotalAmount, PaymentMethod, Status) VALUES (@InvoiceNo, @CustomerID, @Date, @SubTotal, @GST, @Total, @PaymentMethod, 'Completed') SELECT SCOPE_IDENTITY()"
Using cmd As New SqlCommand(invoiceQuery, DBConnection.conn, transaction)
                cmd.Parameters.AddWithValue("@InvoiceNo", txtInvoiceNo.Text)
                cmd.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(cmbCustomer.SelectedValue))
                cmd.Parameters.AddWithValue("@Date", DateTime.Now)
                cmd.Parameters.AddWithValue("@SubTotal", subtotal)
                cmd.Parameters.AddWithValue("@GST", totalGST)
                cmd.Parameters.AddWithValue("@Total", totalAmount)
                cmd.Parameters.AddWithValue("@PaymentMethod", cmbPaymentMethod.Text)
Dim invoiceID As Integer = Convert.ToInt32(cmd.ExecuteScalar())
' Insert Invoice Items
                For Each row As DataRow In dtCart.Rows
                    Dim itemQuery As String = "INSERT INTO InvoiceItems (InvoiceID, ProductID, Quantity, UnitPrice, TotalPrice, GSTAmount) VALUES (@InvoiceID, @ProductID, @Quantity, @UnitPrice, @TotalPrice, @GSTAmount)"
                    Using itemCmd As New SqlCommand(itemQuery, DBConnection.conn, transaction)
                        itemCmd.Parameters.AddWithValue("@InvoiceID", invoiceID)
                        itemCmd.Parameters.AddWithValue("@ProductID", row("ProductID"))
                        itemCmd.Parameters.AddWithValue("@Quantity", row("Quantity"))
                        itemCmd.Parameters.AddWithValue("@UnitPrice", row("UnitPrice"))
                        itemCmd.Parameters.AddWithValue("@TotalPrice", row("Total"))
                        itemCmd.Parameters.AddWithValue("@GSTAmount", 0)
                        itemCmd.ExecuteNonQuery()
                    End Using
                Next
            End Using
transaction.Commit()
            MessageBox.Show("Invoice saved successfully! Invoice No: " & txtInvoiceNo.Text)
' Print receipt
            PrintReceipt()
' Reset form
            ResetForm()
Catch ex As Exception
            transaction.Rollback()
            MessageBox.Show("Error saving invoice: " & ex.Message)
        End Try
Catch ex As Exception
        MessageBox.Show("Database error: " & ex.Message)
    Finally
        DBConnection.CloseConnection()
    End Try
End Sub
Private Sub PrintReceipt()
    ' Simple print preview
    Dim printDialog As New PrintDialog()
    Dim printDocument As New Printing.PrintDocument()
AddHandler printDocument.PrintPage, AddressOf PrintDocument_PrintPage
printDialog.Document = printDocument
    If printDialog.ShowDialog() = DialogResult.OK Then
        printDocument.Print()
    End If
End Sub
Private Sub PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
    Dim font As New Font("Arial", 10)
    Dim titleFont As New Font("Arial", 14, FontStyle.Bold)
    Dim yPos As Single = 50
    Dim leftMargin As Single = 50
    Dim xPos As Single = leftMargin
' Print Header
    e.Graphics.DrawString("BILLING SYSTEM", titleFont, Brushes.Black, xPos, yPos)
    yPos += 30
    e.Graphics.DrawString("Invoice No: " & txtInvoiceNo.Text, font, Brushes.Black, xPos, yPos)
    yPos += 20
    e.Graphics.DrawString("Date: " & DateTime.Now.ToString(), font, Brushes.Black, xPos, yPos)
    yPos += 20
    e.Graphics.DrawString("Customer: " & cmbCustomer.Text, font, Brushes.Black, xPos, yPos)
    yPos += 30
' Print Column Headers
    e.Graphics.DrawString("Product", font, Brushes.Black, xPos, yPos)
    e.Graphics.DrawString("Qty", font, Brushes.Black, xPos + 150, yPos)
    e.Graphics.DrawString("Price", font, Brushes.Black, xPos + 250, yPos)
    e.Graphics.DrawString("Total", font, Brushes.Black, xPos + 350, yPos)
    yPos += 20
    e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos)
    yPos += 10
' Print Items
    For Each row As DataRow In dtCart.Rows
        e.Graphics.DrawString(row("ProductName").ToString(), font, Brushes.Black, xPos, yPos)
        e.Graphics.DrawString(row("Quantity").ToString(), font, Brushes.Black, xPos + 150, yPos)
        e.Graphics.DrawString(CDec(row("UnitPrice")).ToString("N2"), font, Brushes.Black, xPos + 250, yPos)
        e.Graphics.DrawString(CDec(row("Total")).ToString("N2"), font, Brushes.Black, xPos + 350, yPos)
        yPos += 20
    Next
yPos += 10
    e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos)
    yPos += 10
    e.Graphics.DrawString("Grand Total: " & lblGrandTotal.Text, titleFont, Brushes.Black, xPos, yPos)
End Sub
Private Sub ResetForm()
    dtCart.Clear()
    GenerateInvoiceNumber()
    UpdateGrandTotal()
    ClearProductFields()
    cmbCustomer.SelectedIndex = -1
    cmbPaymentMethod.SelectedIndex = -1
End Sub

End Class

A complete VB.NET billing solution typically includes:

| Module | Description | |--------|-------------| | Master Management | Product, Customer, User, Tax (GST/VAT), Company Profile | | Transaction (Billing) | Create/Edit/Print Invoice, Add/Remove Items, Auto-calc totals | | Inventory | Stock-in, Stock-out, Low stock alerts | | Reports | Daily Sales, GST Summary, Customer Ledger, Profit/Loss | | Backup & Security | Database backup, User login, Role-based access |


-- Products Table
CREATE TABLE tbl_Products (
    ProductID INT PRIMARY KEY IDENTITY(1,1),
    ProductName NVARCHAR(100) NOT NULL,
    HSNCode NVARCHAR(20),
    PurchasePrice DECIMAL(18,2),
    SellingPrice DECIMAL(18,2),
    GST_Percent INT, -- e.g., 5, 12, 18, 28
    StockQuantity INT DEFAULT 0
);

-- Customers Table CREATE TABLE tbl_Customers ( CustomerID INT PRIMARY KEY IDENTITY(1,1), CustomerName NVARCHAR(100), Phone NVARCHAR(15), GST_No NVARCHAR(15) -- For B2B invoices ); vb.net billing software source code

-- Invoice Master Table (One invoice per record) CREATE TABLE tbl_Invoice_Master ( InvoiceNo INT PRIMARY KEY IDENTITY(1,1), InvoiceDate DATETIME DEFAULT GETDATE(), CustomerID INT FOREIGN KEY REFERENCES tbl_Customers(CustomerID), SubTotal DECIMAL(18,2), TaxAmount DECIMAL(18,2), GrandTotal DECIMAL(18,2) );

-- Invoice Details Table (Multiple rows per invoice) CREATE TABLE tbl_Invoice_Details ( DetailID INT PRIMARY KEY IDENTITY(1,1), InvoiceNo INT FOREIGN KEY REFERENCES tbl_Invoice_Master(InvoiceNo), ProductID INT FOREIGN KEY REFERENCES tbl_Products(ProductID), Quantity INT, Rate DECIMAL(18,2), Total DECIMAL(18,2) );

In the world of desktop application development, Visual Basic .NET (VB.NET) remains a surprisingly robust and efficient choice for building business applications, particularly billing and invoicing systems. Its rapid application development (RAD) environment, seamless integration with the .NET framework, and ease of database connectivity make it an ideal language for creating point-of-sale (POS) systems, retail billing software, and service invoicing tools. Most VB

If you are searching for "VB.NET billing software source code," you are likely looking to do one of three things: build a custom solution for your business, learn how billing logic works under the hood, or modify an open-source project to fit specific needs.

This article will serve as a deep dive into the architecture, features, database design, and actual code structure of a professional billing software built with VB.NET.

| Aspect | Building from Source Code | Buying Commercial Software | | :--- | :--- | :--- | | Cost | Low (only your time) | High (license fees) | | Customization | Unlimited | Limited to software features | | Time | 2–4 weeks for a stable version | Immediate | | Maintenance | You are responsible | Vendor support | | Learning | High (great for students) | None |

Verdict: If you are a small retail shop with unique workflows (e.g., laundry billing, restaurant split-bill), VB.NET source code gives you freedom. If you need a standard retail POS, buy ready-made software. End Class

Days
Hours
Minutes
Seconds

limited time sale

50% Off On Resolve Master Bundle

limited time 50% Off on Resolve Master Bundle