} // End Sub InsertList public virtual void InsertList <T>(string cmdInsert , System.Collections.Generic.IEnumerable <T> listToInsert , callbackAddData_t <T> addDataCallback) { using (System.Data.Common.DbCommand cmd = this.CreateCommand(cmdInsert)) { InsertList <T>(cmd, listToInsert, addDataCallback); } // End Using cmd } // End Sub InsertList
public static void InsertList <T>(System.Data.IDbCommand cmd , System.Collections.Generic.IEnumerable <T> listToInsert , callbackAddData_t <T> addDataCallback) { using (System.Data.Common.DbConnection conn = GetConnection()) { if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; using (System.Data.Common.DbTransaction transact = conn.BeginTransaction()) { cmd.Transaction = transact; try { foreach (T thisItem in listToInsert) { addDataCallback(cmd, thisItem); if (cmd.ExecuteNonQuery() != 1) { //'handled as needed, //' but this snippet will throw an exception to force a rollback throw new System.InvalidProgramException(); } } // Next thisObject transact.Commit(); } // End Try catch (System.Exception) { transact.Rollback(); throw; } // End Catch finally { if (conn.State != System.Data.ConnectionState.Closed) { conn.Close(); } } // End Finally } // End Using transact } // End Using conn } // End Sub