Thursday, 9 January 2014

ASP.NET

C#- Calculating no. of days by database using SqlDataReader...


    private void NoOfDays()
    {
        con.Open();
        string strupd = "update EmpLeave set NoOFDays=datediff(D, LeaveFromDate, LeaveTillDate)where Emp_Id='" + txtEmpId.Text.ToString() + "'";
        cmd = new SqlCommand(strupd, con);
        cmd.ExecuteNonQuery();
        con.Close(); con.Open();
        cmd = new SqlCommand("select EmpLeave.NoOFDays from EmpLeave,Emp_Profile where Emp_Profile.Emp_Id=EmpLeave.Emp_Id and EmpLeave.Emp_Id='" + txtEmpId.Text.ToString() + "'", con);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
          lblTotal.Text = "DAYS : "+ dr["NoOFDays"].ToString();
        }
        dr.Close();
        con.Close();
    }

No comments:

Post a Comment

Thanks for comments.