private void InsertData(DataTable dt) { int UpdateCount = 0, InsertCount = 0; try { for (int i = 0; i < dt.Rows.Count; i++) { #region Value Initialization CountryName = dt.Rows[i][CountryNameColumn].ToString().Trim(); StateName = dt.Rows[i][StateNameColumn].ToString().Trim(); Description = dt.Rows[i][DescriptionColumn].ToString().Trim(); #endregion var objCountry = new Country() { CountryName = CountryName.ToLower(), eStatus = (int)eStatus.Active }.SelectList <Country>()[0]; DataTable dtState = new Query() { CountryId = objCountry.CountryId, StateName = StateName, eStatusNot = (int)eStatus.Delete }.Select(eSP.qry_State); var objState = new State() { CountryId = objCountry.CountryId, StateId = dtState.Rows.Count > 0 ? dtState.Rows[0][CS.StateId].zToInt() : (int?)null, StateName = StateName.zFirstCharToUpper(), Description = Description, }; if (objState.StateId.HasValue) { objState.Update(); UpdateCount++; } else { objState.eStatus = (int)eStatus.Active; objState.Insert(); InsertCount++; } } CU.SetSuccessExcelMessage(InsertCount, UpdateCount, "State"); } catch (Exception ex) { CU.ZMessage(eMsgType.Error, string.Empty, ex.Message, 0); } LoadStateGrid(ePageIndex.Custom); }