Example #1
0
        public int ExcuteNotQuery(string sqlStr, IList <List <DbParameter> > lstParmeters, DBtransaction dbtran)
        {
            int num   = 0;
            int count = lstParmeters.Count;

            try
            {
                for (int i = 0; i < count; i++)
                {
                    DbCommand dbCommand = providerFactory.CreateCommand();
                    dbCommand.CommandText = sqlStr;
                    dbCommand.Connection  = dbtran.DbConnection;
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.Transaction = dbtran.DbTransaction;
                    if (lstParmeters[i] != null && lstParmeters[i].Count > 0)
                    {
                        dbCommand.Parameters.AddRange(lstParmeters[i].ToArray());
                    }
                    num += dbCommand.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("'" + sqlStr + "'" + "执行错误!" + ex);
            }
            finally {
                if (dbtran != null)
                {
                    dbtran.RollBack();
                }
            }
            return(num);
        }
Example #2
0
        public int ExcuteNotQuery(string sqlStr, List <DbParameter> Parmeters, DBtransaction dbtran)
        {
            int       result    = 0;
            DbCommand dbCommand = providerFactory.CreateCommand();

            try
            {
                dbCommand.CommandText    = sqlStr;
                dbCommand.CommandType    = CommandType.Text;
                dbCommand.Connection     = dbtran.DbConnection;
                dbCommand.Transaction    = dbtran.DbTransaction;
                dbCommand.CommandTimeout = commandTimeOut;

                if (Parmeters != null && Parmeters.Count > 0)
                {
                    dbCommand.Parameters.AddRange(Parmeters.ToArray());
                }
                result = dbCommand.ExecuteNonQuery();
                dbCommand.Parameters.Clear();  // 清空参数
                dbCommand.Connection.Close();  //关闭Command
            }
            catch (Exception ex)
            {
                if (dbCommand != null && dbCommand.Connection.State == ConnectionState.Open)
                {
                    dbtran.RollBack();
                    dbCommand.Transaction.Dispose();
                    dbCommand.Connection.Close();
                }
                throw ex;
            }
            finally
            {
            }
            return(result);
        }