Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

vb6 - Recordset .value property

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...