public int Insert(List <PERMITDC> objPERMITs, ref List <EXCEPTIONDC> lstExceptions) { int insertedCount = 0; DBConnection objConnection = new DBConnection(); PERMITDA objPERMITDA = new PERMITDA(); try { foreach (PERMITDC obj in objPERMITs) { try { objConnection.Open(true); insertedCount = objPERMITDA.Insert(objConnection, obj); objConnection.Commit(); } catch (Exception exp) { EXCEPTIONDC objExcption = new EXCEPTIONDC(); objExcption.FIELD_ID = obj.PERMIT_ID; objExcption.EXCEPTION_MESSAGE = exp.Message; objExcption.STACK_TRACK = exp.StackTrace; lstExceptions.Add(objExcption); objConnection.Rollback(); } } if (lstExceptions.Count > 0) { throw new Exception(lstExceptions[0].EXCEPTION_MESSAGE); } } catch (Exception exp) { throw exp; } finally { objConnection.Close(); } return(insertedCount); }