In this post we learn how to Sum a complete SQL Server column. That means Sum result we want to see in tax box of VB.net. Suppose we have an Amount column. In which many amounts are written. And we have to plus it only once so we will use the given coding. This coding is especially useful for our invoice application and banking software etc. It is used only for data type number. That is, the column of the SQL service which contains only the data type number. To create this project we need to use a number of tax boxes and a button.

Imports System.Data.SqlClient Imports System.Data.Sql Imports System.IO Public Class Form1 Dim constr1 As String = "paste connection string" Dim cn As New SqlConnection(constr1) Dim cmd As New SqlCommand Dim dr As SqlDataAdapter Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim cmd As New SqlCommand cmd.Connection = cn cmd.CommandText = "Select Sum(Amount) as AmountSum from Table3" Dim adapter As New SqlDataAdapter(cmd) Dim table As New DataTable() adapter.Fill(table) If table.Rows.Count() > 0 Then TextBox1.Text = table.Rows(0)("AmountSum").ToString() End If End Sub End Class
 
Top