Jump to content

Asp Using Javascript Variables Binding To Record Set


Guest Zephan

Recommended Posts

Guest Zephan

This one is driving me nuts... I am using an ADODB recordset (Server.CreateObject("ADODB.Recordset")) in the attached code. When I assgin a record set field value to a variable (testset = fitRS("testsetID");), the variable ends up being "bound" to the record set field value? If you look at the attached code (about 20 lines up from the bottom), I "Response.Write" out the variable "testset" (which was set to fitRS("testsetID") earlier in the code) just before and just after doing a fitRS.MoveNext(). In the output, the testset variable ends up changing automatically as I move through the record set (as if bound)? If I do the same code in VBScript, this does not happen. What the heck is happening here? By the way, if I change the line where I set testset = fitRS("testsetID") to a "dummy" expression on the right, testset = fitRS("testsetID") + 0, then the variable no longer acts as if it is "bound" to the record set field. The "bound variable" action is keeping my inner while loop from ever ending until it reaches "EOF", instead of exiting when the record set field value changes from one value to the next (because the while condition uses the recordset field value and the variable which ends up the same). I there a way to get the "variable binding" action to stop without using a "dummy" expression?

<%@  language="JAVASCRIPT" %><%    //Declare Variables    var fitConn;         // Fitness Connection Object    var fitRS;           // Recordset for fitness records    var resultsRS;       // Recordset for Result values    var strConnection;   // Fitness Connection string to access the database    var i;               // a counter variable    var testset;         // test set number    // -- Create objects    fitConn = Server.CreateObject("ADODB.Connection");    fitRS = Server.CreateObject("ADODB.Recordset");    // --- Open Connection to database    strConnection = "DSN=FitnessData";    fitConn.Open(strConnection);    // Populate fitRS    strSQL = "SELECT * FROM [AllRecords] WHERE dbo.AllRecords.ID > 0 ORDER BY [testsetID], [Name], [dueDate] DESC, [TestID]"    fitRS.CursorType = 3;    fitRS.LockType = 1;    fitRS.Open(strSQL, fitConn);%><html><head>    <title>TEST</title>    <link rel="stylesheet" type="text/css" href="fitlog.css" /></head><body>    <%    //Create a separte table for each test set    while (!fitRS.EOF) {[b]        testset = fitRS("testsetID");[/b]        //Build table for current testset        Response.Write("<table class=\"logTable\" border=1>");                //Create Header Row for this test        Response.Write("<TR class=\"headerRow\">");        Response.Write("<TH width=160>Name</TH>");        Response.Write("<TH width=400>Debug</TH>");        Response.Write("</TR>");                while ([b]fitRS("testsetID") == testset[/b]) {            Response.Write("<TR class=\"completeRecord\">");            //Output the data for a row            Response.Write("<TD nowrap=\"nowrap\">" + fitRS("name") + "</TD>");                        //Second Column using for debugging            Response.Write("<TD nowrap=\"nowrap\">");[b]        Response.Write("Before MoveNext: " + testset);            fitRS.MoveNext();            Response.Write(" - After MoveNext: " + testset);[/b]            if (fitRS.EOF) {                Response.Write("-->EOF");                break;            }        }        Response.Write("</table>");    }        // Close and purge fitRS and fitConn    Response.Write("CLOSE");    fitRS.Close();    fitRS = null;    fitConn.Close();    fitConn = null;    %></body></html>

Link to comment
Share on other sites

It shouldn't do that, but it might because you're setting it to an object instead of a value. It might set a reference to the object instead of copying it. To specify the value, instead of this:testset = fitRS("testsetID");do this:testset = fitRS.fields.item("testsetID").value;Doing it the first way actually returns the field object instead of just the value of the field (I think it's an ADODB.Field object). It's possible that setting it to the object would set a reference to the fitRS object, although I wouldn't expect that behavior. Javascript might work a little differently when it's Microsoft JScript. For what it's worth though, I write the vast majority of my classic ASP code using Javascript also, and I always use the fields.item version to get a recordset value.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...