Public Function getConnection() As SqlConnection Return New SqlConnection(connString) End Function
Private Sub AddProductToCart(productID As Integer, qty As Integer) 'Fetch product details from database using productID Dim query As String = "SELECT ProductName, SellingPrice, GST_Percent FROM tbl_Products WHERE ProductID = " & productID Using conn As SqlConnection = getConnection() conn.Open() Using cmd As New SqlCommand(query, conn) Dim reader As SqlDataReader = cmd.ExecuteReader() If reader.Read() Then Dim productName As String = reader("ProductName").ToString() Dim price As Decimal = Convert.ToDecimal(reader("SellingPrice")) Dim gstPercent As Integer = Convert.ToInt32(reader("GST_Percent")) 'Add row to DataGridView (dgvCart) dgvCart.Rows.Add(productID, productName, qty, price, qty * price, gstPercent) CalculateTotal() 'Update subtotal, tax, grand total End If End Using End Using End Sub vb.net billing software source code
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. Conclusion The "vb.net billing software source code" is not just a collection of files; it is a blueprint for understanding transactional systems, database integrity, and UI/UX in desktop applications. By mastering the code patterns shown above—database transactions, DataGridView cart management, and dynamic printing—you can build a billing system that rivals commercial products. Insert into tbl_Invoice_Details for each row in cart
Private Sub SaveInvoice() Using conn As SqlConnection = getConnection() conn.Open() Dim transaction As SqlTransaction = conn.BeginTransaction() Try '1. Insert into tbl_Invoice_Master Dim masterQuery As String = "INSERT INTO tbl_Invoice_Master (InvoiceDate, CustomerID, SubTotal, TaxAmount, GrandTotal) " & "VALUES (@date, @custID, @sub, @tax, @grand); SELECT SCOPE_IDENTITY();" Dim newInvoiceNo As Integer = 0 Using cmdMaster As New SqlCommand(masterQuery, conn, transaction) cmdMaster.Parameters.AddWithValue("@date", DateTime.Now) cmdMaster.Parameters.AddWithValue("@custID", GetCurrentCustomerID()) 'Function to get selected customer ID cmdMaster.Parameters.AddWithValue("@sub", lblSubTotal.Text) cmdMaster.Parameters.AddWithValue("@tax", lblTax.Text) cmdMaster.Parameters.AddWithValue("@grand", lblGrandTotal.Text) newInvoiceNo = Convert.ToInt32(cmdMaster.ExecuteScalar()) End Using '2. Insert into tbl_Invoice_Details for each row in cart Dim detailsQuery As String = "INSERT INTO tbl_Invoice_Details (InvoiceNo, ProductID, Quantity, Rate, Total) " & "VALUES (@invNo, @prodID, @qty, @rate, @total)" For Each row As DataGridViewRow In dgvCart.Rows Using cmdDetails As New SqlCommand(detailsQuery, conn, transaction) cmdDetails.Parameters.AddWithValue("@invNo", newInvoiceNo) cmdDetails.Parameters.AddWithValue("@prodID", row.Cells("ProductID").Value) cmdDetails.Parameters.AddWithValue("@qty", row.Cells("Quantity").Value) cmdDetails.Parameters.AddWithValue("@rate", row.Cells("Rate").Value) cmdDetails.Parameters.AddWithValue("@total", row.Cells("Total").Value) cmdDetails.ExecuteNonQuery() '3. Update stock in tbl_Products Dim stockQuery As String = "UPDATE tbl_Products SET StockQuantity = StockQuantity - @qty WHERE ProductID = @prodID" Using cmdStock As New SqlCommand(stockQuery, conn, transaction) cmdStock.Parameters.AddWithValue("@qty", row.Cells("Quantity").Value) cmdStock.Parameters.AddWithValue("@prodID", row.Cells("ProductID").Value) cmdStock.ExecuteNonQuery() End Using End Using Next transaction.Commit() MessageBox.Show("Invoice saved successfully. Invoice No: " & newInvoiceNo) ClearCart() Catch ex As Exception transaction.Rollback() MessageBox.Show("Failed to save invoice: " & ex.Message) End Try End Using End Sub The final piece is printing. Using the PrintDocument component from the toolbox: Total) " & "VALUES (@invNo