Below is the structured, production-ready backend code for your billing form. It manages real-time math calculations, populates data grids dynamically, and safely updates the database using transaction queries. Database Connection Module ( dbConnection.vb )
If you don't want to start from scratch, many open-source and learning-oriented projects are available. Search for the following terms on , SourceForge , or CodeProject :
: Ability to store products, categories, and stock levels.
Key implementation tips (VB.NET specifics)
If you want to scale this code into a complete point-of-sale system, let me know. I can provide the source code extensions for directly to POS hardware, implementing user login permissions , or adding low-stock system alerts . Share public link
Modules to store customer details (name, contact) and inventory levels with shorthand notations.
Private Sub SaveInvoice() OpenDB() Dim transaction As SqlTransaction = conn.BeginTransaction() Try ' 1. Insert into Invoice Master Dim invoiceNo As Integer = GetNextInvoiceNumber() ' custom function Dim masterQuery As String = "INSERT INTO tbl_Invoice_Master VALUES(@invNo, @date, @custID, @sub, @discPct, @tax, @grand)" cmd = New SqlCommand(masterQuery, conn, transaction) cmd.Parameters.AddWithValue("@invNo", invoiceNo) cmd.Parameters.AddWithValue("@date", DateTime.Now) cmd.Parameters.AddWithValue("@custID", cmbCustomer.SelectedValue) cmd.Parameters.AddWithValue("@sub", lblSubtotal.Text) cmd.Parameters.AddWithValue("@discPct", txtDiscountPercent.Text) cmd.Parameters.AddWithValue("@tax", lblTax.Text) cmd.Parameters.AddWithValue("@grand", lblGrandTotal.Text) cmd.ExecuteNonQuery() ' 2. Insert details For Each row As DataGridViewRow In dgvBill.Rows If row.IsNewRow Then Continue For Dim detailQuery As String = "INSERT INTO tbl_Invoice_Details (InvoiceNo, ProductID, Quantity, Rate, Amount) VALUES(@invNo, @pid, @qty, @rate, @amt)" cmd = New SqlCommand(detailQuery, conn, transaction) cmd.Parameters.AddWithValue("@invNo", invoiceNo) cmd.Parameters.AddWithValue("@pid", row.Cells("ProductID").Value) cmd.Parameters.AddWithValue("@qty", row.Cells("Quantity").Value) cmd.Parameters.AddWithValue("@rate", row.Cells("Rate").Value) cmd.Parameters.AddWithValue("@amt", row.Cells("Amount").Value) cmd.ExecuteNonQuery()
This layer handles the connection to the database. VB.NET uses System.Data.SqlClient to interact with SQL Server.
This SDK allows you to treat an Excel file as a template and populate it with data from your billing system. The SDK then converts the spreadsheet into a professional invoice PDF . This is a very flexible approach because non-developers can design the invoice's layout directly in Excel.
"The lack of a layered architecture makes the application brittle. For example, if the database schema changes, modifications are required directly in the UI event handlers (e.g., BtnSave_Click ), violating the Open/Closed Principle."
| Priority | Action Item | Estimated Effort | | :--- | :--- | :--- | | | Replace string-concatenated SQL with Parameterized Queries immediately. | High | | High | Extract Business Logic into a separate Class Library project. | Medium | | High | Implement global Exception Handling and Logging (e.g., Log4Net or NLog). | Low | | Medium | Standardize Naming Conventions and rename UI controls. | Low | | Low | Implement Async/Await for database calls to improve UI responsiveness. | Medium |
In the world of small to medium-sized enterprises (SMEs), billing and invoicing remain the backbone of daily operations. While cloud-based SaaS solutions dominate the headlines, many businesses still prefer—or require—a fast, reliable, offline-capable desktop application.
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.