Microsoft KB Archive/195193

= PRB: Recordset.MoveNext Changes Variable in JavaScript =

Article ID: 195193

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6

-



This article was previously published under Q195193



SYMPTOMS
When you use JavaScript to set a variable equal to a field value in a Recordset object--that is, myField = RS.Fields("FieldName")--the value in the variable changes when a rs.MoveNext is performed.



CAUSE
In JavaScript, Recordset.Fields returns an ADO Field object rather than the value stored in that field, thus when an RS.MoveNext is performed, the values in the properties of the Field object are changed, most notably the .value property.



RESOLUTION
Use the .value property if your intention is to return the value of the field in the recordset object rather than a Field object, as in the following example:   LastFieldName = RS.Fields("FieldName").value;



STATUS
This behavior is by design.



MORE INFORMATION
The following Active Server Pages (ASP) sample code demonstrates how to return the value of the field in the Recordset object.  var RS1 = Server.CreateObject("ADODB.RECORDSET") RS1.ActiveConnection = "DSN=Pubs" RS1.Open ("select * from authors") myVal = RS1.Fields("au_lname").value //Remove the .value //to change myVal. Response.Write ((myVal) + "") RS1.MoveNext Response.Write (myVal) 

Keywords: kbdatabase kbprb KB195193

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.