How to assign the result of a query to a sample of a database variable?

I make a request through the TADOQuery component:

SQLQuery9.SQL.Text := 'SELECT id FROM details ORDER BY `id` DESC limit 1'; b := SQLQuery9; // присваиваю результат переменной 

- gives an error on startup.

    1 answer 1

    First, you need to open the query - SQLQuery9.Open
    data can be obtained via SQLQuery9.FieldValues['id']

    Full code:

     SQLQuery9.SQL.Text := 'SELECT id FROM details ORDER BY `id` DESC limit 1'; SQLQuery9.Open; b := SQLQuery9.FieldValues['id']; 

    PS In the example, there is no check for the presence of a result. This is outside the scope of the question asked.