Employee Class
public class Employee
{
public int id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string DeptName { get; set; }
}
EmployeeData access layer Class
public class EmployeeDATAACCESSLAYER
{
public static List<Employee> GetAllemployee()
{
List<Employee> employees = new List<Employee>();
string CS = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("select id,Name,Gender,DeptName from tblEmployees", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Employee emp = new Employee();
emp.id = Convert.ToInt32(rdr["id"]);
emp.Name = rdr["Name"].ToString();
emp.Gender = rdr["Gender"].ToString();
emp.DeptName = rdr["DeptName"].ToString();
employees.Add(emp);
}
}
return employees;
}// method end.......................................
}
No comments:
Post a Comment