public Object DelCode(string CodeString) { ReturnData result = new ReturnData(); result.Msg = ""; using (var sqlconnection = new SqlConnection(connectionString)) { bool flag = true; if (sqlconnection.State == ConnectionState.Closed) { sqlconnection.Open(); } SqlTransaction transaction = sqlconnection.BeginTransaction(); try { CodeService repository = new CodeService(sqlconnection); for (int i = 0; i < CodeString.Split(',').Length; i++) { string strCodeString = (CodeString.Split(','))[i].ToString(); if (!repository.DelCode((CodeString.Split(','))[i].ToString(), transaction)) { flag = false; break; } } if (flag) { transaction.Commit(); result.Result = true; } else { result.Result = false; } return(result); } catch (Exception ex) { transaction.Rollback(); result.Msg = ex.Message; result.Result = false; return(result); } finally { sqlconnection.Close(); } } }