Exemplo n.º 1
0
        public int ExcuteSQL(string strSQL, ParamMap param)
        {
            object         val         = 0;
            IDbTransaction transaction = null;
            IDbConnection  connection  = null;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                connection = GetConnection();
                {
                    connection = GetConnection();

                    IDbDataParameter[] parms = param.toDbParameters();

                    if (AdoHelper.DbType == DatabaseType.ACCESS)
                    {
                        strSQL = SQLBuilderHelper.builderAccessSQL(strSQL, parms);
                        val    = AdoHelper.ExecuteNonQuery(connection, transaction, CommandType.Text, strSQL);
                    }
                    else
                    {
                        val = AdoHelper.ExecuteNonQuery(connection, transaction, CommandType.Text, strSQL, parms);
                    }
                }
            }
            catch (Exception e)
            {
                DBLOG.error(strSQL, e);
            }
            return(Convert.ToInt32(val));
        }
Exemplo n.º 2
0
        public int Count(string strSQL)
        {
            int           count      = 0;
            IDbConnection connection = null;

            try
            {
                connection = GetConnection();
                {
                    connection = GetConnection();
                    count      = Execute(strSQL);
                }
            }
            catch (Exception ex)
            {
                DBLOG.error(strSQL, ex);
            }

            return(count);
        }
Exemplo n.º 3
0
        private int Execute(MySqlCommand cmd)
        {
            DBLOG.log(cmd.CommandText);
            IDbConnection conn = this.GetConnection();

            cmd.Connection = conn as MySqlConnection;

            int re = 0;

            try
            {
                re = cmd.ExecuteNonQuery();

                /*
                 * StringBuilder str = new StringBuilder();
                 * //cmd.Parameters.RemoveAt("item");
                 * foreach (MySqlParameter o in cmd.Parameters)
                 * {
                 *  str.Append(o.ParameterName).Append("=").Append(o.Value.ToString()).Append("&");
                 * }
                 * DBLOG.log(str.ToString());*/
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错3:", mysqle);// + JSON.Encode(cmd.Parameters),mysqle);

                StringBuilder str = new StringBuilder();
                //cmd.Parameters.RemoveAt("item");
                foreach (MySqlParameter o in cmd.Parameters)
                {
                    str.Append(o.ParameterName).Append("=").Append(o.Value.ToString());
                }
                DBLOG.error(str.ToString());
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错4" + ioe.Message, ioe);
                conn.Close();
            }
            return(re);
        }
Exemplo n.º 4
0
        private int Execute(string sql)
        {
            DBLOG.log("Execute:" + sql);
            IDbConnection conn = this.GetConnection();
            int           re   = 0;
            MySqlCommand  cmd  = new MySqlCommand(sql, (MySqlConnection)conn);

            try
            {
                re = cmd.ExecuteNonQuery();
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错3:", mysqle);
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错4", ioe);
                conn.Close();
            }

            return(re);
        }
Exemplo n.º 5
0
        public int ExcuteSQL(string strSQL)
        {
            int val = 0;

            DBLOG.log("ExcuteSQL>" + strSQL);
            IDbConnection connection = null;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                connection = GetConnection();
                val        = new MySqlCommand(strSQL, connection as MySqlConnection).ExecuteNonQuery();// AdoHelper.ExecuteNonQuery(connection, null, CommandType.Text, strSQL);
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错ExcuteSQL:", mysqle);
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错5", ioe);
                connection.Close();
            }
            return(val);
        }
Exemplo n.º 6
0
        public int Insert <T>(List <T> entityList)
        {
            if (entityList == null || entityList.Count == 0)
            {
                return(0);
            }

            int val = 0;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                foreach (T t in entityList)
                {
                    val += Insert <T>(t);
                }
            }
            catch (Exception e)
            {
                DBLOG.error("Insert=" + entityList, e);
            }

            return(val);
        }