1

请参阅下面的 DDL:

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

请参阅下面的 ADODB 记录集:

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

rs("bookingdate")指定和 和有什么区别rs("bookingdate").value。我在这里阅读了一些问题,回答者说总是使用 .value,但没有解释原因。我查看了 MSDN,但找不到答案。

4

1 回答 1

2

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.

于 2013-10-05T17:18:59.800 回答