PRB: Recordset.MoveNext Changes Variable in JavaScriptID: Q195193
|
When using 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.
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.
Use the ".value" property if your intention is to return the value of the field in the recordset object rather than a Field Object, for example:
LastFieldName = RS.Fields("FieldName").value;
This behavior is by design.
The following Active Server Pages (ASP) sample code demonstrates how to return the value of the field in the recordset object.
<SCRIPT LANGUAGE=javascript RUNAT=Server>
var RS1 = Server.CreateObject("ADODB.RECORDSET")
RS1.ActiveConnection = "DSN=mtslab"
RS1.Open ("select * from authors")
myVal = RS1.Fields("au_lname").value //remove the .value
//to change myVal
Response.Write ((myVal) + "<BR>")
RS1.MoveNext()
Response.Write (myVal)
</SCRIPT>
Keywords : kbADO kbASP kbJScript kbVisID100 kbVisID600 kbGrpASP
Version : WINDOWS:1.0,6.0; WINNT:
Platform : WINDOWS winnt
Issue type : kbprb
Last Reviewed: May 10, 1999