コード例 #1
0
    public static List <SegmentoEmpresa> Listar(int pintIdIdioma = 0, int pintId = 0)
    {
        string        strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString;
        SqlConnection objConexao         = new SqlConnection(strConectionString);

        SqlCommand objComando = new SqlCommand("SPE_L_SEGMENTO_EMPRESA");

        objComando.Connection  = objConexao;
        objComando.CommandType = CommandType.StoredProcedure;

        ///Parametros
        if (pintIdIdioma > 0)
        {
            objComando.Parameters.Add("@idiomaId", SqlDbType.Int).Value = pintIdIdioma;
        }
        if (pintId > 0)
        {
            objComando.Parameters.Add("@segmentoEmpresaId", SqlDbType.Int).Value = pintId;
        }

        try
        {
            //Abre Conexao
            objConexao.Open();

            //Declara variavel de retorno
            List <SegmentoEmpresa> objList = new List <SegmentoEmpresa>();
            SegmentoEmpresa        obj     = default(SegmentoEmpresa);

            IDataReader idrReader = default(IDataReader);

            idrReader = objComando.ExecuteReader();

            while ((idrReader.Read()))
            {
                obj = new SegmentoEmpresa();
                obj.FromIDataReader(idrReader);
                objList.Add(obj);
            }

            return(objList);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            //Fecha a conexao se aberta
            if (objConexao.State != ConnectionState.Closed)
            {
                objConexao.Close();
            }
        }
    }