Results 1 to 37 of 37

Thread: sorting a recordset

  1. #1

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216

    sorting a recordset

    how do i use
    VB Code:
    1. dtaData.Recordset.sort
    i want to sort by the field called "Last Name" within the recordset

  2. #2
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Are you using ADO?
    "If at first you don't succeed, then skydiving is not for you"

  3. #3

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    no im just using the data control in the toolbox - i know it may not be the best way to go but .... meh.

    can u help me plz?

  4. #4
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    from MSDN

    Sort Property


    Specifies one or more field names on which the Recordset is sorted, and whether each field is sorted in ascending or descending order.

    Settings and Return Values

    Sets or returns a String of comma-separated field names to sort on, where each name is a Field in the Recordset, and is optionally followed by a blank and the keyword ASC or DESC, which specifies the field sort order.

    Remarks

    The data is not physically rearranged, but is simply accessed in the sorted order.

    A temporary index will be created for each field specified in the Sort property if the CursorLocation property is set to adUseClient and an index does not already exist.

    Setting the Sort property to an empty string will reset the rows to their original order and delete temporary indexes. Existing indexes will not be deleted.

    The field cannot be named "ASC" or "DESC" because those names conflict with the keywords ASC and DESC. Give a field with a conflicting name an alias by using the AS keyword in the query that returns the Recordset.
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  5. #5

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    thanks zuperman that helps me understand exactly what it does - but it still doensn't solve my problem because i don't know the code to use. ive tried dtaData.recordset.sort = "Last Name ASC" but it always gives me and error

  6. #6
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Are you using a datagrid as well?
    "If at first you don't succeed, then skydiving is not for you"

  7. #7

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    no datagrid

    its for a sports points keeper - textboxes are set to the data control

  8. #8
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    What is the field you want to sort on?
    "If at first you don't succeed, then skydiving is not for you"

  9. #9

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    "Last Name"

  10. #10
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Originally posted by aldinator
    "Last Name"
    Ok, just put the name of ADODC control like
    VB Code:
    1. ADODC1.Recordset.Sort = "Last Name"

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  11. #11

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    k thanks but is there a way to do it without adodc control? im using the regular data control

  12. #12
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Originally posted by aldinator
    k thanks but is there a way to do it without adodc control? im using the regular data control
    What version of VB are you running. I was only aware of the ADO databound control. I am nor familiar with the one you say you are using. Please tell me the exact name of the component you are using.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  13. #13

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    im using vb6 - its always in the toolbox to the left of the OLE control

  14. #14
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    You have me stumped. I have the object browser to the left of OLE. Unless you're talking about the Data View Window in which case that is a totally different concept.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  15. #15
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    Sorting a recordset incurs fairly high cpu usage. Your best bet would be to sort on the database backend.
    - If at first you dont succeed, then give up, cause you will never will!

  16. #16

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    here:
    Attached Images Attached Images  
    Last edited by aldinator; Oct 26th, 2002 at 09:57 PM.

  17. #17
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its because the field name is two words, try enclosing it in bracets:

    dtaData.Recordset.sort="[Last Name]"

    When designing your database I find that two word names for fields aren't worth the hassle and should be avoided.

  18. #18

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    edneeis: i have tried that with no success - even with a one-word field it doesn't work

  19. #19
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What error are you getting exactly?

    Also here is other info on sorting: http://www.vbforums.com/showthread.p...sort+recordset

  20. #20

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    the error is:
    Attached Images Attached Images  

  21. #21
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Maybe you can only sort clientside cursors. What kind of database are you using?

    This is from the help:
    You can use the Sort property with dynaset- and snapshot-type Recordset objects....
    ...The Sort property doesn't apply to table- or forward-only–type Recordset objects. To sort a table-type Recordset object, use the Index property.
    Just for the record I think DAO is of the devil by the way.

  22. #22
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Is there any reason why you cant change the data control to a ADO data control. The functionality is far greater and I dont think you would have to change any other code.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  23. #23

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    theres no reason why i couldn't change it - its just that ive never used it before

    edneeis - thanks alot i think thats the info i needed - but ho would i use the index property to sort my table?

  24. #24
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Originally posted by aldinator
    theres no reason why i couldn't change it - its just that ive never used it before
    It looks and acts exactly the same except I have just created 2 projects binding a text box to the surname of a table.
    The standard data control will not sort but the ADO one works like a charm.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  25. #25
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by aldinator
    theres no reason why i couldn't change it - its just that ive never used it before

    edneeis - thanks alot i think thats the info i needed - but ho would i use the index property to sort my table?
    I don't know its been too many moons since I've had to use DAO. I'd take Mega up on his suggestion. You'll probably have to change the connection string, but not that much else.

  26. #26

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    k thanks a lot and im gonna try it right now.

    ill get back to you in about 5 minutes

  27. #27

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    im getting some errors

    i don't know if ADO is going to work too great for this app... cause its done - im just adding some finishing touches...

    so edneeis could you figure out what the index thing msn was talking about

  28. #28
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    This is likely to be my last posting on this.. for tonight anyway. So one pointer.

    1. Set the sort on the recordset when the form opens, not when you doing a .Movenext

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  29. #29

    Thread Starter
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay!!!!!!!!!!

    i did it!!!

    incase anyones wondering how i did it....
    i changed the index value of Last Name to Yes(allow duplicates) and then used dtaData.recordset.index = "Last Name" and voila!!


  30. #30
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    Good stuff
    - If at first you dont succeed, then give up, cause you will never will!

  31. #31
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Hey all, I'm having a problem sorting a recordset, with a ADODB opened through code. I keep getting "object or provider does not support this type of op." or something like that. adOpenDynamic, and adLockOptimistic, are being used. The field I want to sort by is indexed. Any ideas?

  32. #32
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    India
    Posts
    342
    CursorLocation should be set to adUseClient
    ksm

  33. #33
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Thanks, I'll try it.

  34. #34
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Should it be adOpenDynamic, adUseClient ? Because I'm still getting the same error mess.

  35. #35
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    India
    Posts
    342
    try with adOpenStatic ...

    whts the error msg ur getting??
    ksm

  36. #36
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    "Object or provider is not capable of performing requested op."

  37. #37
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    I tried static, dynamic, etc. Perhaps server-side cursor? Security set to false, even though this is not an updating function. Merely a sort. Would it be more practical to sort the grid? Can you even sort a flexgrid? I use that for the search, rather than the rs.

Posting Permissions

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



Click Here to Expand Forum to Full Width