Closed Thread
Results 1 to 3 of 3

Thread: Insert into DBGrid

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Insert into DBGrid

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: Insert into DBGrid

    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.

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Insert into DBGrid

    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Effortlessly sort columns in DBGrid & Datagrid??
    By Andrern2000 in forum Visual Basic Programming
    Replies: 1
    Last Post: 10-28-2010, 06:28 AM
  2. how do ia insert the </br> tag on PHP?
    By lil-fino in forum PHP Development
    Replies: 2
    Last Post: 04-03-2010, 11:54 AM
  3. borland c++ builder 5, dbgrid question
    By totonex in forum C and C++
    Replies: 2
    Last Post: 03-27-2009, 11:40 AM
  4. Replies: 8
    Last Post: 11-30-2008, 10:22 PM
  5. DBGrid displaying problem
    By ReekenX in forum Pascal and Delphi
    Replies: 3
    Last Post: 05-05-2008, 09:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts