Private Sub Form16_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim sqlquery As String = "SELECT SUM(price) AS totalprice FROM expenses"
        Dim sqlcommand As New OleDbCommand
        With sqlcommand
            .CommandText = sqlquery
            .Connection = conn
            .ExecuteNonQuery()
        End With
        Label2.Text= 'totalprice that is SUM(price)
    End Sub

    i want to display sum(price) in label2...how to do this plz help..
Private Sub Form16_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim strAccessConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.MDB"
        Dim sqlquery As String = "SELECT SUM(price) AS totalprice FROM expenses"

        Dim myDataSet As DataSet = new DataSet()
        Dim myAccessConn As OleDbConnection = Nothing
        Try
             myAccessConn = new OleDbConnection(strAccessConn)
             Dim sqlcommand As New OleDbCommand(sqlquery,myAccessConn)
             Dim myDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(sqlcommand)

             myAccessConn.Open()
             myDataAdapter.Fill(myDataSet)
             myAccessConn.Close()


        Dim q = (From c In myDataSet.Tables(0).AsEnumerable
                Select New With {.totalprice = c.Field(Of Decimal)("totalprice")}).FirstOrDefault

        If q IsNot Nothing Then
            Label2.Text = q.totalprice.ToString()
        End If


        Catch
        End Try






    End Sub
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.