Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • husdy 1 post 21 karma points
    Mar 12, 2021 @ 23:17
    husdy
    0

    Retrieve a row from a database table

    How can I get a row from a database table in umbraco 8 and put it in an API.

  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    Mar 15, 2021 @ 07:12
    AddWeb Solution Pvt. Ltd
    0

    Hello husdy,

    Refer this example:-

    var query = new Sql().Select("*").From("people");
    

    You should be able to fetch the data something like this:

    public IEnumerable<Person> GetAll()
    {
    using (var scope = Current.ScopeProvider.CreateScope(autoComplete: true))
    {
    var sql = new Sql("SELECT * FROM person"); //{Put query as per your requirement}
    var people = scope.Database.Fetch<Person>(sql);
    return people;
    }
    
    return null;
    }
    

    If you only need to read data you can use autoComplete: true (default is false, where you also need to scope.Complete(); inside the using statement.

Please Sign in or register to post replies

Write your reply to:

Draft