private void btnSave_Click_1(object sender, EventArgs e) { try { foreach (DataGridViewRow cb in grdList.Rows) { if (cb.Cells[3].Value == null) { MessageBox.Show("Please enter attendence for all Employees!!!"); return; } } attendance att = new attendance(); List <attendance> attlstnew = new List <attendance>(); List <attendance> attlstupdt = new List <attendance>(); AttendanceDB docDB = new AttendanceDB(); foreach (DataGridViewRow dgvrw in grdList.Rows) { if (changedval.ContainsKey(dgvrw.Cells[1].Value.ToString())) { if (Initval.ContainsKey(dgvrw.Cells[1].Value.ToString())) { att = new attendance(); att.EmployeeID = dgvrw.Cells[1].Value.ToString(); att.AttendenceStatus = dgvrw.Cells[3].Value.ToString(); attlstupdt.Add(att); } else { att = new attendance(); att.EmployeeID = dgvrw.Cells[1].Value.ToString(); att.AttendenceStatus = dgvrw.Cells[3].Value.ToString(); attlstnew.Add(att); } } } DateTime dt = UpdateTable.getSQLDateTime(); if (Main.itemPriv[2]) { dt = dtpdate.Value; } if (docDB.UpdateAttendance(attlstupdt, attlstnew, empstatuslist, dt)) { MessageBox.Show("Attendance Status Updated"); changedval.Clear(); Initval.Clear(); ListEmployee(); } else { MessageBox.Show("Error Updating Attendance Status"); } } catch (Exception) { MessageBox.Show("Failed Adding / Editing User Data"); } }