Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: field value property


Message #1 by "Pieter" <pieter.schockaert@c...> on Mon, 12 Nov 2001 13:02:22
Hi,



Can someone explain the difference between:

x = myrecordset("number") and x = myrecordset("number").value?

The first and the latter give the same result when I do a Response.write

(x) in the loop through the record set.

When I do a Response.write(x) after the loop the first way does nothing (x 

seems to be out of scope). The second method produces the correct result.



best regards,

Pieter
Message #2 by "Ken Schaefer" <ken@a...> on Tue, 13 Nov 2001 11:56:21 +1100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Pieter" <pieter.schockaert@c...>

Subject: [access_asp] field value property





: Can someone explain the difference between:

: x = myrecordset("number") and x = myrecordset("number").value?

: The first and the latter give the same result when I do a Response.write

: (x) in the loop through the record set.

: When I do a Response.write(x) after the loop the first way does nothing (x

: seems to be out of scope). The second method produces the correct result.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



VB (and VBScript) has this things called default properties.



objRS.Fields("fieldname").Value

is the same as:

objRS("fieldname")



because the Fields collection is the default property of the recordset

object, and the .Value property is the default property of the Field object.

Likewise .Contents is the default property of the Session object, so you can

do:



Session("myVar") = "some value"



which is the same as



Session.Contents("myVar") = "some value"



Now, as to why "it is not working" one way, -vs- the other, you really need

to provide code that you are using, so we can see what you're trying to do.



Cheers

Ken



Message #3 by "Pieter" <pieter.schockaert@c...> on Tue, 13 Nov 2001 08:28:48
while (!rs.EOF)

{  cpt++;

if(cpt==1){ first=rs("number").value;}

                     last=rs("number").value;

                    xml+="<customer><number>"+ rs("number") 

+"</number><company>"+ rs("company") +"</company><city>"+ rs("city") 

+"</city><contact>"+ rs("contact") +"</contact><active>"+ rs("active") 

+"</active></customer>";

                     rs.MoveNext();

                 }

Message #4 by "Pieter" <pieter.schockaert@c...> on Tue, 13 Nov 2001 08:35:29
Thanks for your reply!

Here is the JScript code (with the value property):



while (!rs.EOF)

{  cpt++;

   if(cpt==1) first=rs("number").value;

   last=rs("number").value;

   xml+="<customer><number>"+ rs("number") +"</number><company>"+ rs

("company") +"</company><city>"+ rs("city") +"</city><contact>"+ rs

("contact") +"</contact><active>"+ rs("active") +"</active></customer>";

    rs.MoveNext();

}

Response.write(first);



Maybe it's because rs("number") is an object (and has to be allocated) and 

rs("number").value is a variable.



regards,

Pieter



PS: please ignore the previous message (I clicked the post button too 

early)
Message #5 by "Ken Schaefer" <ken@a...> on Wed, 14 Nov 2001 10:42:52 +1100
JScript doesn't support default properties, so you are getting an object

reference.



I think you need to do objRS.Fields("fieldname").Value

(but I'm not a jscript expert, so YMMV)



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Pieter" <pieter.schockaert@c...>

Subject: [access_asp] Re: field value property





: Thanks for your reply!

: Here is the JScript code (with the value property):

:

: while (!rs.EOF)

: {  cpt++;

:    if(cpt==1) first=rs("number").value;

:    last=rs("number").value;

:    xml+="<customer><number>"+ rs("number") +"</number><company>"+ rs

: ("company") +"</company><city>"+ rs("city") +"</city><contact>"+ rs

: ("contact") +"</contact><active>"+ rs("active") +"</active></customer>";

:     rs.MoveNext();

: }

: Response.write(first);

:

: Maybe it's because rs("number") is an object (and has to be allocated) and

: rs("number").value is a variable.

:

: regards,

: Pieter

:

: PS: please ignore the previous message (I clicked the post button too

: early)







  Return to Index