int SecBeat2 = _service.GetBeatBySector_Id(sectorId).Count(); for (int i = 1; i <= SecBeat2; i++ ) { var bsec4 = _service.GetAllBeatStatus().Where(x => x.Date == dt && x.Sector_Id == sectorId && x.Shift == 1).FirstOrDefault(); if (bsec4 != null) { Employee emp = _service.GetEmployee(bsec4.Employee_Id); Beat beat = beats.FirstOrDefault(x => x.Id == bsec4.Beat_Id && x.Sector_Id == sectorId); dataset.Beat.Rows.Add( emp.Name, emp.Id, emp.CellNo //bs1.HasWireless ); } else { dataset.Beat.Rows.Add("", "", ""); } }