locked
How to display data from db in list RRS feed

  • Question

  • User932259438 posted

    Hi,

    My code:

        public List<Voznik> voznik(string username, string password, int IdPodjetja)
        {
            Voznik result = new Voznik();
          //  if (Membership.ValidateUser(username, password) && IdPodjetja != null)
           // {
               //voznik
                var result = (from c in db.tbl_zaposlenis
                             where c.Idkreiranopodjetje == IdPodjetja
                             orderby c.Priimek
                             select new 
                             {
                                 ID = c.ID,
                                 ImeVoznik = c.Priimek + " " + c.Ime
    
                             });
    
                //foreach (var item in result)
                //{
    
                //}
    
    
           // }
            return result;
        }
        public class Voznik
        {
            public int ID { get; set; }
            public string Priimek { get; set; }
            public string Ime { get; set; }
            public string Naslov { get; set; }
            public int PostnaStevilka { get; set; }
            public string Kraj { get; set; }
            public string DavcnaStevilka { get; set; }
            public string DelovnoMesto { get; set; }
            public bool chkOdredilPotovanje { get; set; }
            public bool chkRezident { get; set; }
    
            public string ImeVoznik { get; set; }
        }

    I need to display all from db in list.

    How to do this?

    Wednesday, January 15, 2020 7:25 AM

Answers

  • User932259438 posted

    public class PrikazVoznik {
    public string priimek { get; set; }
    public string ime { get; set; }
    };

    [WebMethod]
    public List<PrikazVoznik> voznik(int IdPodjetja, string username, string password)
    {
    List<PrikazVoznik> result = null;
    if (Membership.ValidateUser(username, password) && IdPodjetja != null)
    {

    result =(from t1 in db.tbl_zaposlenis
    where t1.Idkreiranopodjetje == IdPodjetja
    select new PrikazVoznik { priimek=t1.Priimek, ime=t1.Ime }).ToList();

    };

    return result;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 15, 2020 11:16 AM

All replies

  • User932259438 posted

    I resolved with my code:

            if (Membership.ValidateUser(username, password) && IdPodjetja != null)
            {
    
                var result = from t1 in db.tbl_zaposlenis
                             where t1.Idkreiranopodjetje==IdPodjetja
                              select new PrikazVoznik { Priimek=t1.Priimek };
    
                
    
            };
    
            return result.ToList();

    but after add if membership.validate return result.ToList() as not  exists..

    I tried like this:

            List<PrikazVoznik> result = new <List<PrikazVoznik>; 
            if (Membership.ValidateUser(username, password) && IdPodjetja != null)
            {

    Not works...

    Wednesday, January 15, 2020 9:26 AM
  • User932259438 posted

    public class PrikazVoznik {
    public string priimek { get; set; }
    public string ime { get; set; }
    };

    [WebMethod]
    public List<PrikazVoznik> voznik(int IdPodjetja, string username, string password)
    {
    List<PrikazVoznik> result = null;
    if (Membership.ValidateUser(username, password) && IdPodjetja != null)
    {

    result =(from t1 in db.tbl_zaposlenis
    where t1.Idkreiranopodjetje == IdPodjetja
    select new PrikazVoznik { priimek=t1.Priimek, ime=t1.Ime }).ToList();

    };

    return result;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 15, 2020 11:16 AM