i have the following code that isn't working correct

Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            con.ConnectionString = "Data Source=" & ServerV & ";Initial Catalog=" & databaseV & ";Persist Security Info=True;User ID=" & usernameV & ";Password=" & passwordV & ""
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT SUM (QtyInvoiced) as Volume FROM ArTrnDetail GROUP BY Customer, TrnYear HAVING(Customer = '1055') AND (TrnYear = 2011)"
            Dim lrd As SqlDataReader = cmd.ExecuteReader()
            While lrd.Read()

                Me.LBprevYearVOL.Text = Convert.ToString(lrd("Volume"))

            End While
        Catch ex As Exception
            MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
        Finally
            con.Close()
        End Try
    End Sub

please can someone tell me what i am doing wrong. i get a error invalid coloum name SUM

with the following line

cmd.CommandText = "SELECT SUM (QtyInvoiced) AS Volume FROM ArTrnDetail GROUP BY Customer, TrnYear HAVING(Customer = '" & Me.LBCustomer.Text & "') AND (TrnYear =" & Me.CBOPrevYear.SelectedText & ")"

i get incorrect santex near ')'

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.