Ok the problem has been solved
Now the sum is also correct against the First name and the Last name ,and also solved the Shaggy Hiker and a Shaggy Runner thing.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!") ElseIf Lastname_txt.Text.Trim = "" Then MsgBox("Last name Cannot be Blank!") Else con.Open() cmd = New SqlCommand(str, con) cmd.Connection = con cmd.CommandText = "SELECT * FROM Employee where Firstname ='" & Firstname_txt.Text.Trim & "' and Lastname ='" & Lastname_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!") Dim str, str1 As String str1 = "Select Employeecode from Employee where Firstname = '" & Firstname_txt.Text.Trim & "' and Lastname = '" & Lastname_txt.Text.Trim & "';" cmd = New SqlCommand(str1, con) cmd.Connection = con dr = cmd.ExecuteReader While dr.Read Empcode.Text = dr(0) End While con.Close() con.Open() str = "SELECT SUM(Present) FROM Attendance WHERE AttendanceStatus = 1 And Firstname = '" & Firstname_txt.Text.Trim & "';" cmd = New SqlCommand(str, con) cmd.Connection = con Dim _dr As SqlDataReader _dr = cmd.ExecuteReader While _dr.Read TextBox1.Text = _dr(0) End While con.Close() Else MsgBox("This Employee does not Exists!") Firstname_txt.Text = "" Lastname_txt.Text = "" End If End If con.Close() End Sub
Thank you all for guiding me and helping me to solve this issue.many more to come hehe .




Reply With Quote