Ejemplo n.º 1
0
        public EmpDto getEmployee(int id)
        {
            EmpDto employee = new EmpDto();

            using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand getEmp = new SqlCommand("Select Name from Employees where Id = " + id, sqlConnection))
                {
                    sqlConnection.Open();
                    var reader = getEmp.ExecuteReader();
                    while (reader.Read())
                    {
                        employee.Id         = reader.GetInt32(0);
                        employee.Name       = reader.GetString(1);
                        employee.Department = reader.GetString(2);
                    }
                }
            }
            return(employee);
        }
Ejemplo n.º 2
0
        public List <EmpDto> GetEmps()
        {
            List <EmpDto> emps = new List <EmpDto>();

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                using (SqlCommand getAll = new SqlCommand("Select * From Employees", conn))
                {
                    conn.Open();
                    var reader = getAll.ExecuteReader();
                    while (reader.Read())
                    {
                        EmpDto employee = new EmpDto();
                        employee.Id         = reader.GetInt32(0);
                        employee.Name       = reader.GetString(1);
                        employee.Department = reader.GetString(2);
                        emps.Add(employee);
                    }
                }
            }
            return(emps);
        }