//desplegar por id public Area ObtenerAreaById(int IDArea) { DatoArea datArea = new DatoArea(); //dos formas de hacerlo //LINQ Area aut = new Area(); aut = (from l in datArea.select_All_Area() where l.IDArea == IDArea select l).FirstOrDefault(); return aut; //por medio del procedimiento almacenado //return datAuto.select_AutosbyId(IDAuto); }
public Area select_AutosbyId(int IDArea) { // Autos ObjAuto = new Autos(); Area ObjArea = new Area(); string StoredProcedure = "ObtenerAreaByID"; 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 = "IDArea"; param.Value = IDArea; cmd.Parameters.Add(param); con.Open(); using (DbDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { ObjArea = new Area(IDArea, (string)dr["NombreArea"]); } } } } return ObjArea; }