示例#1
0
        /// <summary>
        /// 返回受影响的行数
        /// </summary>
        /// <param name="sql">存储过程名称或则纯sql语句</param>
        /// <param name="cmdType">CommandType 【SQL脚本Text】  【简单存储过程StoredProcedure】</param>
        /// <param name="pms"></param>
        /// <returns></returns>
        public int ExecuteNoquery(string sql, CommandType cmdType, params SqlParameter[] pms)
        {
            try
            {
                WriteDataBase.OpenSharedConnection();
                int flentCount = 0;
                try
                {
                    using (var cmd = WriteDataBase.CreateCommand(WriteDataBase._sharedConnection, sql, true, pms))
                    {
                        cmd.CommandType = cmdType;

                        if (pms != null && pms.Count() > 0)
                        {
                            cmd.Parameters.Clear();
                            foreach (SqlParameter item in pms)
                            {
                                cmd.Parameters.Add(item);
                            }
                        }
                        flentCount = cmd.ExecuteNonQuery();
                        return(flentCount);
                    }
                }
                catch (Exception ex)
                {
                    //todu.....异常日志,关闭连接
                    log.Info("ExecuteNoquery:" + ex);
                }
                finally
                {
                    WriteDataBase.CloseSharedConnection();
                }
                return(flentCount);
            }
            catch (Exception ex)
            {
                log.Info("ExecuteNoquery:" + ex);
            }
            finally
            {
                //todu.....异常日志,关闭连接
                WriteDataBase.CloseSharedConnection();
            }
            return(0);
        }