If I do ADOTable.insert, it inserts it one before the selected row, is there a command which inserts it one after the selected row?
Thanks
ADOTable.Next;
ADOTable.Insert;
Of course, in a relational SQL DB, rows have no particular order, unless sorted by a column. So "before" and "after" don't count or matter. It's unordered. The next time you view your table, the order may be any order whatsoever. The database may rearrange records as it sees fit to be in whatever order. Most databases have an implicit record number that it orders the table by if no other sort order is specified. This order is usually the order in which records were inserted. The databse doesn't have to enforce this, however, so don't count on it. If you want a specific order, you must add an "order" column (or something like that) and sort on it.
For instance:
Table parents:
ID Name
1 Fred
2 John
Table Kids:
ID Parent Order Name
1 1 2 Jack
2 2 1 Jill
3 1 1 Jake
4 2 2 Jane
Now you can select Fred's kids in "order" with
SELECT * FROM kids WHERE parent=1 ORDER BY order
produces:
ID Parent Order Name
3 1 1 Jake
2 1 2 Jill
As you see, the rows now have an order. You could also instead sort by an "implicit" order, such as date of birth (which is age), or any other value you like. By using an "order" column, however, you can order in any order without relying on the contents of records. This way, I can in this case for instance swap Jill and Jake, no matter how old they are, or any other property of them.
To summarize, the above code is sillyness, and useless. The order you see on your screen when inserting isn't important and doesnt matter and is irrelevant and not dependable.
Yeh, I realised after that when i insert it, it doesnt really matter, since the table is sorted anyways.
But I just thought it would be nice to have it so that when the insert button is clicked, the row appears at the bottom. I am doing this via the DBGrid by the way.
Thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks