Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27156

VS 2010 SUM() Sql query

$
0
0
Hi,

CODE:
Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        Dim adaptor As New SqlDataAdapter
        Dim dataset As New DataSet
        con.Open()
        con.Close()
        If Firstname_txt.Text = "" Then
            MsgBox("Firstname Cannot be blank!")
        Else
            con.Open()
            cmd = New SqlCommand(str, con)
            cmd.Connection = con
            cmd.CommandText = "SELECT Firstname FROM Attendance where Firstname ='" & Firstname_txt.Text.Trim & "'"
            cmd.Connection = con
            adaptor.SelectCommand = cmd
            adaptor.Fill(dataset, "O")
            Dim count = dataset.Tables(0).Rows.Count
            If count > 0 Then
                MessageBox.Show("This Employee Does Exist!")
                cmd.CommandText = "SELECT SUM(Present) FROM Attendance WHERE AttendanceStatus = 1 And (Firstname = Firstname) Group BY Firstname"
                cmd = New SqlCommand(cmd.CommandText, con)
                cmd.Connection = con
                dr = cmd.ExecuteReader
                While dr.Read
                    TextBox1.Text = dr(0)
                    'TextBox4.Text = dr(1)
                End While
                con.Close()
            Else
                MsgBox("This Employee does not Exists!")
                Firstname_txt.Text = ""
            End If
        End If

            con.Close()
    End Sub
End Class

Help needed with this Sql command
CODE:
Code:

  cmd.CommandText = "SELECT SUM(Present) FROM Attendance WHERE AttendanceStatus = 1 And (Firstname = Firstname) Group BY Firstname"
I want see the sum(Number of attended days of AttendanceStatus Field where column data is 1(1 denotes present here),I can see the data but it gets incremented by 1 or some times it shows the correct data for some Employee name ,but others they are just 1 number behind or 1 number incremented.I don't know why?

Viewing all articles
Browse latest Browse all 27156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>