Recordset .value property

2019-01-07 01:20发布

问题:

Please see the DDL below:

CREATE TABLE TestDate (bookingdate datetime)
INSERT INTO TestDate VALUES ('2013-10-04')

Please see the ADODB recordset below:

rs.open "SELECT bookingdate FROM TestDate"
If rs("bookingdate") > dateadd("yyyy", -6, Now)
  msgbox("test")
end if

What is the difference between specifying rs("bookingdate") and rs("bookingdate").value. I have read some questions on here where answerers say always use .value, but it is not explained why. I had a look on MSDN but could not find an answer.

回答1:

Value is the default property of the Field object, so in VB6 there is no difference between rs("bookingdate") and rs("bookingdate").value when used without Set.

I personally prefer not using default properties that don't take parameters. It makes the code less confusing IMO.

In VB.NET the default property must have a parameter, so this situation does not occur.
Note Recordset has such default property with parameter, and you are using it to return the Field object: rs("bookingdate") is actually rs.Item("bookingdate"). Using those, IMO, makes no harm.



标签: vb6