Exemple #1
0
 public virtual void InsertList <T>(string cmdInsert
                                    , System.Collections.Generic.IEnumerable <T> listToInsert
                                    , callbackAddDataClosure_t <T> addDataCallback)
 {
     using (System.Data.Common.DbCommand cmd = this.CreateCommand(cmdInsert))
     {
         InsertList <T>(cmd, listToInsert, addDataCallback);
     }
 } // End Sub InsertList
Exemple #2
0
        } // End Sub InsertList

        public virtual void InsertList <T>(System.Data.IDbCommand cmdInsert
                                           , System.Collections.Generic.IEnumerable <T> listToInsert
                                           , callbackAddDataClosure_t <T> addDataCallback)
        {
            using (System.Data.Common.DbConnection conn = this.Connection)
            {
                if (conn.State != System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }

                cmdInsert.Connection = conn;

                using (System.Data.Common.DbTransaction transact = conn.BeginTransaction())
                {
                    cmdInsert.Transaction = transact;

                    try
                    {
                        foreach (T thisItem in listToInsert)
                        {
                            addDataCallback(thisItem);

                            if (cmdInsert.ExecuteNonQuery() != 1)
                            {
                                //'handled as needed,
                                //' but this snippet will throw an exception to force a rollback
                                throw new System.InvalidProgramException();
                            } // End if (cmdInsert.ExecuteNonQuery() != 1)
                        }     // 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 InsertList