Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    Pune, India
    Posts
    5

    Question Unanswered: Recordsets Usage

    My database table has a field "Code". I can refer to the field by rs!Code as well as rs("Code") (rs is the recordset object defined). Can anyone tell me the difference between the two approaches mentioned above i.e. rs!Code and rs("Code").

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by sourabh_d
    My database table has a field "Code". I can refer to the field by rs!Code as well as rs("Code") (rs is the recordset object defined). Can anyone tell me the difference between the two approaches mentioned above i.e. rs!Code and rs("Code").
    VB offers several "shortcut" methods for using objects.

    In the case of a recordset, the full useage is

    rs.Fields!ColumnName

    This method ensures that no matter what, the data returned will be correct.

    I remember seeing (some time ago) that it's possible to change the default property of a control, and if you do, these shortcuts may return unexpected results.

    From a performance viewpoint, there isn't any difference between rs!code and rs.Fields!Code and rs("code") and rs("code").Value

    The rs("Code") format does allow you to provide field names externally to the app.

    Interstingly, there is another option, often used in iterating through the field values, which is to refer to the column number. This approach IS about 10% faster than refering to the column name.

    Code:
    For N = 0 to rs.Fields.Count-1
      Debug.Print rs.Fields(N).Name, rs.Field(N).Value
    Next N
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

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