Board index » delphi » Sorting tables doesn't work WHY?

Sorting tables doesn't work WHY?

I want to sort a table called soort on field soort and did:

     form1.query2.close;
     form1.query2.sql.clear;
     form1.query2.sql.add ('select * from soort order by soort');
     form1.query2.execsql;

also tried form1.query2.sql.open but did do the job.

suggestions ?

 

Re:Sorting tables doesn't work WHY?


If your dataset is on a form you don't have to add the Form1 designation on the
front of the Query object.  

ExecSql is not designed to return a Dataset, it's to be used with Inserts,
updates and Deletes.

You may want to try naming your column that you are sorting by something
different than the table name.  It isn't good practice to have a column name
the same as your table name.

********************************
Michael Glatz
glatzfa...@aol.com
mgl...@briefcase.com

Re:Sorting tables doesn't work WHY?


Firstly, you shouldn't be using ExecSQL in this context. Query2.Open is
correct.

Secondly, if the query and the procedure are both on Form1, you don't need
to reference the form - it's taken for granted.

Thirdly, even if your query only makes use of one table, I recommend that
you always reference the table before each field name. You can do this by
means of an alias in the FROM clause. (Sometimes you may need to enclose the
field name in quotes, too.)

Try this:

    with Query2 do
    begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from Soort S');
        SQL.Add('Order by S.Soort');
        Open;
    end;

--
Stephen Brown
sbr...@sprocket.win-uk.net

Quote
Marco wrote in message <3602BC47.78D95...@hotmail.com>...
>I want to sort a table called soort on field soort and did:

>     form1.query2.close;
>     form1.query2.sql.clear;
>     form1.query2.sql.add ('select * from soort order by soort');
>     form1.query2.execsql;

>also tried form1.query2.sql.open but did do the job.

Other Threads