Results 1 to 8 of 8

Thread: rs!FieldName or rs.Fields("FieldName")

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    rs!FieldName or rs.Fields("FieldName")

    Ok, I forget. Which is the faster or better way of getting a value from a recordset?

    rs!FieldName or rs.Fields("FieldName")

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Allegedly, it's supposed to be the ! format, but I don't see how or why, and it always makes me nervous. I usualy opt for the .FIelds() route.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I always use the ! method. I think it more a matter of what you are comfortable with.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I heard that the .Fields was faster performing
    so I changed over to using it that way.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    I prefer rst("field name")...

    As to the speed - no idea, should be negligable anyway.
    If it is a major speed difference, please post up so I can change


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    I always use rs.fields("fieldname"). Like Vince says, I'm sure any difference will be undetectable. Unless anyone knows different!
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  7. #7
    New Member
    Join Date
    Aug 2004
    Posts
    4
    I think I ran into problems when using ! in the past - for example if a field name contained unusual characters, this caused the VB IDE a bit of grief. Obviously a well designed database shouldn't use weird character sets for field names, but I was linking to a third party database, and didn't have any control over it.

    Another possible reason to stick to .Fields("name") is to future proof your code - I think the .NET code conversion utility ignores !, (at least it did in the early versions, MS might have addressed this now).

    George

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    MS Told me that using ordinals is faster.

    objrs.Fields(0).Value > objrs.Fields("fieldname") > objrs!fieldname

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