I have a TADODataSet
that loads some columns from the DB (a SP, but that does not matter). e.g:
SELECT A, B, C, D FROM Foo
Now, after I open the dataset, Is it possible to change the order of fields (or swap them) in that TADODataSet
so that it will contain e.g:
C, D, A, B
I want to do it without changing the command text itself. Is it possible?
You can use the Index
property of the TField
class to set the desired order.
Example:
MyDataset.FieldByName('C').Index := 0;
MyDataset.FieldByName('D').Index := 1;
MyDataset.FieldByName('A').Index := 2;
MyDataset.FieldByName('B').Index := 3;
This also works if the fields are persistent:
MyDatasetC.Index := 0;
MyDatasetD.Index := 1;
MyDatasetA.Index := 2;
MyDatasetB.Index := 3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With