Re: Accessing database records from VB
- From: "Damian" <damian.brierley@xxxxxxxxxxxxxx>
- Date: Fri, 9 Mar 2007 12:05:13 -0000
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..."
.
- References:
- Accessing database records from VB
- From: Damian
- Re: Accessing database records from VB
- From: Bob Butler
- Accessing database records from VB
- Prev by Date: Re: Accessing database records from VB
- Next by Date: Application crashing when doing a database update via DAO.
- Previous by thread: Re: Accessing database records from VB
- Next by thread: Application crashing when doing a database update via DAO.
- Index(es):
Relevant Pages
|