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()
        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 Count(Present),Firstname FROM Attendance WHERE (AttandenceID = AttandenceID) 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)

            End While
            con.Close()
        Else
            MsgBox("This Employee does not Exists!")
        End If
        con.Close()
    End Sub

Now the problem is that whenever I click the Count result is not the same as in Database (IF the present days are 3 then it shows 4..it automatically gets incremented by 1.
In my database if the person is Present then it's value will be 1
Present is 1
and absent is 0
Absent is 0
I want to calculate how many presents days are there in a month(TO calculate sallary)
I have
AttandanceID Field
Firstname Field
Present Field
Absent Field
AttandanceDate Field

In short, what you should do is either use SUM(Present) or use WHERE Present = 1. COUNT just counts the number of rows in the result set.

Thanks a lot :) It works like a charm

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.