Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
How to get accepted in Fileice (200% Working) 22/2012
Premium Account
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
ExecuteCommandBatch
<pre class='prettyprint' language='cs'>static class SqlExec { public static void ExecCommandBatch(System.Data.Common.DbConnection conn, System.Data.IsolationLevel isolation, ExceptionFailSafeEventHandler<System.Exception> failSafe, params System.Data.Common.DbCommand[] cmds) { if ((conn == null)) throw new System.ArgumentNullException("conn"); if ((cmds.Length < 2)) throw new System.ArgumentException("Must supply more than one Command"); // TODO: validate isolation? bool success = false; BatchCommandFailedException excp = null; ExceptionFailSafeEventArgs<System.Exception> args = new ExceptionFailSafeEventArgs<System.Exception>(); int totalAffectedRows = 0; int length = cmds.Length - 1; int i; if ((conn.State != ConnectionState.Open)) conn.Open(); DbTransaction trans; try { trans = conn.BeginTransaction(isolation); } catch (System.Exception ex) { trans = conn.BeginTransaction(); } for (i = 0; i <= length; i++) { cmds[i].Connection = conn; cmds[i].Transaction = trans; } try { for (i = 0; i <= length; i++) { totalAffectedRows += cmds[i].ExecuteNonQuery(); } success = true; } catch (System.Exception ex) { excp = new BatchCommandFailedException(cmds[i], i, ex); } finally { if (success) { trans.Commit(); } else { trans.Rollback(); totalAffectedRows = 0; args.Exception = excp.InnerException; if (failSafe != null) failSafe.Invoke(typeof(SqlExec), args); } trans.Dispose(); foreach (DbCommand cmd in cmds) { cmd.Dispose(); } conn.Close(); conn.Dispose(); if (excp != null) if (args.Throw) throw excp; } //Return totalAffectedRows? } } public delegate void ExceptionFailSafeEventHandler<T>(object sender, ExceptionFailSafeEventArgs<T> e) where T : System.Exception; public class ExceptionFailSafeEventArgs<T> : System.EventArgs where T : System.Exception { private T _data; private bool _throw = true; public bool Throw { get { return _throw; } set { _throw = value; } } public ExceptionFailSafeEventArgs() : this(null) { } public ExceptionFailSafeEventArgs(T ex) : base() { _data = ex; } public T Exception { get { return _data; } set { _data = value; } } } [Serializable()] public class BatchCommandFailedException : DbException { public BatchCommandFailedException(string message) : base("Command execution has failed. Reason: " + message){ } public BatchCommandFailedException(string message, DbCommand cmd) : base(string.Format("Command execution for command '{0}' has failed. Reason: " + message, cmd.CommandText)){ } public BatchCommandFailedException(DbCommand cmd) : base(string.Format("Command execution for command '{0}' has failed.", cmd.CommandText)){ } public BatchCommandFailedException(DbCommand cmd, int ordinal) : base(string.Format("Command execution for command {0}: '{1}' has failed.", ordinal, cmd.CommandText)){ } public BatchCommandFailedException(DbCommand cmd, int ordinal, Exception inner) : base(string.Format("Command execution for command {0}: '{1}' has failed. Reason: {2}", ordinal, cmd.CommandText, inner.Message), inner){ } public BatchCommandFailedException(string message, Exception inner) : base(message, inner){ } public BatchCommandFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context){ } }</pre> <a href="http://www.refactormycode.com/codes/96-executecommandbatch" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>