0
   Try
con.Open()
            MsgBox(con)
            qry = "Select sum(slpri) From sales where slsnum > '" & 10000 & "'"
            cmd = New MySqlCommand(qry, con)
            dr = cmd.ExecuteReader()
            If dr.Read() Then
                sum1 = (dr("slpri").ToString)
                stotxt.Text = sum1
            End If
            con.Close()
        Catch ex As Exception
            MsgBox("ERROR:" + ex.Message, MsgBoxStyle.Exclamation, "ERROR")
            con.Close()
        End Try            

Edited by John_92

2
Contributors
1
Reply
10
Views
1 Year
Discussion Span
Last Post by Reverend Jim
0

I presume the error is from

sum1 = (dr("slpri").ToString)

My guess is that you haven't specified a field name for the SUM in the query. I'm not that familiar with mysql but you could try either changing the query to

qry = "Select total=sum(slpri) From sales where slsnum > '" & 10000 & "'"

then using

stotxt.Text = dr("total")

or (this may work) leaving the query as is and using

stotxt.Text = dr(0)

Edited by Reverend Jim

This topic has been dead for over six months. 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.