Re: Accessing database records from VB

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks everyone for the explaination. I suspected there was some legacy
involved as I took over an old VB5 application...

Changed them all to RecordValue = recordset("Record").value as that was
what I had mostly used anyway :)

Damian


"Bob Butler" <tiredofit@xxxxxxxxxxx> wrote in message
news:eqw3qsYYHHA.992@xxxxxxxxxxxxxxxxxxxxxxx
"Damian" <damian.brierley@xxxxxxxxxxxxxx> wrote in message
news:45f0100e$1_1@xxxxxxxxxxxxxxxxxxxxxx
Hello all,

Is there any difference/usage problems with the following methods of
accessing records in a database?:

RecordValue = recordset("Record").value

That's the most explicit of what you have posted

RecordValue = recordset!Record

That's an older style that is less used in recent years although it has
it's
adherents. I dislike it because you can't use the numeric index which
means
that your code may sometimes use that format and sometimes another and
inconsistency makes code harder to work with. Admittedly not a major
issue
but every little bit helps.

Additionally, that syntax returns the Field object, not the value. VB
then
has to locate the default property (.Value) in order to get the value.
That
adds ambiguity to the code since in some cases you may be referring to the
Field and in other cases the Value.

RecordVaule = recordset("Record").

That's functionally equivalent to the ! syntax except that it allows use
of
string or numeric arguments. It still suffers from relying on the default
property.

I have seen all 3 used with the same recordset in some code and all
work!

Yep. The ! syntax tells VB to find the default property for the object
and
use the argument as the index so
rs!field is the same as rs.fields(field) and since VB will continue
looking
for default properties the .Value is often optional.

You left off the syntax that I would use:
rs.fields("field").Value

which is itself still shorthand for the full syntax:
rs.fields.item("field").Value

--
Reply to the group so all can participate
VB.Net: "Fool me once..."



.



Relevant Pages

  • Re: Problems with SELECT from JOIN - OT
    ... > One gets the GameId field object, the other gets the Pct_Used field value ... > mostly preference, if not purely preference ... If I use the rs!literal syntax then I can not use a ... Dim oJunk As Junk: ...
    (microsoft.public.vb.database)
  • Re: Problems with SELECT from JOIN - OT
    ... One gets the GameId field object, the other gets the Pct_Used field value ... mostly preference, if not purely preference ... By using the explicit format (I bend so far as to omit ... If I use the rs!literal syntax then I can not use a variable ...
    (microsoft.public.vb.database)
  • Re: Accessing database records from VB
    ... That's the most explicit of what you have posted ... I dislike it because you can't use the numeric index which means ... Additionally, that syntax returns the Field object, not the value. ...
    (microsoft.public.vb.database)