Get a single record from SQL Server the correct way

前端 未结 3 1522
孤独总比滥情好
孤独总比滥情好 2021-02-15 16:52

I\'m using Ado to retrieve a single record by id. Observe:

public async Task GetImage(int id)
{
    var image = new Image();

    using (SqlConnecti         


        
3条回答
  •  爱一瞬间的悲伤
    2021-02-15 17:01

    You can use Top(1) in this case in your query to get only single record from database:

    SELECT Top(1) * FROM Images 
    where id = @id
    order by id desc -- will get the latest record
    

提交回复
热议问题