Exemplo n.º 1
0
        //desplegar por id
        public Personal ObtenerPersonalById(int IDPersonal)
        {
            DatoPersonal datPersonal = new DatoPersonal();
            //dos formas de hacerlo
            //LINQ
            Personal aut = new Personal();
            aut = (from l in datPersonal.select_All_Personal()
                   where l.IDPersonal == IDPersonal
                   select l).FirstOrDefault();

            return aut;
            //por medio del procedimiento almacenado
            //return datAuto.select_AutosbyId(IDAuto);
        }
Exemplo n.º 2
0
        public Personal select_AutosbyId(int IDPersonal)
        {
            // Autos ObjAuto = new Autos();
            Personal ObjAuto = new Personal();
            string StoredProcedure = "ObtenerPersonalByID";

            using (DbConnection con = dpf.CreateConnection())
            {

                con.ConnectionString = constr;
                using (DbCommand cmd = dpf.CreateCommand())
                {

                    cmd.Connection = con;
                    cmd.CommandText = StoredProcedure;
                    cmd.CommandType = CommandType.StoredProcedure;
                    DbParameter param = cmd.CreateParameter();
                    param.DbType = DbType.Int32;
                    param.ParameterName = "IDPersonal";
                    param.Value = IDPersonal;
                    cmd.Parameters.Add(param);
                    con.Open();
                    using (DbDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            ObjAuto = new Personal(IDPersonal, (string)dr["CIPersonal"], (string)dr["Nombre"], (string)dr["Apellido"]
                                , (string)dr["Telefono"], (string)dr["Email"], (int)dr["IDArea"]);

                        }

                    }
                }
            }
            return ObjAuto;
        }