0

hi,
Does anyone know how to accumulate total in sql.I have made a function to add a amount to sql.i wants the amount which i have add to be accumulated in total column in sql.How do i make it work.
please help

Public Function Update_TotalBalance() As Boolean
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim strSQL As String = ""
        Dim connStr As String

        connStr = "server=(local); database=Credit; Trusted_Connection=yes"

        myConnection = New SqlConnection(connStr)

        Try

        strSQL = "INSERT INTO dbo.RetailerBalance([BoothID], [GrandTotal]) VALUES ('" & Form1.txtBoothID.Text & "','" & frmCurrentBalance.lblBalance.Text & "')"

        If myConnection.State = 0 Then
            myConnection.Open()
        End If


         myCommand = New SqlCommand(strSQL, myConnection)
        myCommand.ExecuteNonQuery()
        myCommand.CommandText = strSQL


        Catch e As Exception
            MsgBox(Err.Description)
        End Try

        myConnection.Close()

    End Function

Edited by swathys: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by swathys
0

SQL has a function called SUM(), which does exactly what the name implies.
So, in your SQL string you can do this:

INSERT INTO dbo.RetailerBalance([BoothID], [GrandTotal], [Accumulated]) VALUES ('" & Form1.txtBoothID.Text & "','" & frmCurrentBalance.lblBalance.Text & "',SUM([GrandTotal]))
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.