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

Recommended Answers

All 2 Replies

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]))

hi,
thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.