var SecBeat = _service.GetBeatBySector_Id(sectorId); foreach (var Sb in SecBeat) { dataset.SectorBeat.Rows.Add(Sb.Name); } var bs = _service.GetAllBeatStatus().Where(x => x.Date == dt && x.Sector_Id == sectorId && x.Shift == 1).ToList(); if (bs != null) { foreach (var bsec in bs) { Employee emp = _service.GetEmployee(bsec.Employee_Id); Beat beat = beats.FirstOrDefault(x => x.Id == bsec.Beat_Id && x.Sector_Id == sectorId); dataset.Beat.Rows.Add(beat.Name, emp.Name, emp.Id, emp.CellNo // bs.HasWireless ); } } else { foreach (var bsec in bs) { dataset.Beat.Rows.Add("", "", ""); } }