Results 1 to 6 of 6

Thread: Need help urgent! SELECT NEWID() Expires?

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Need help urgent! SELECT NEWID() Expires?

    Ok... I have this statement here.

    Code:
    strSQL = "";
    strSQL += "SELECT NEWID() AS 'uidSubjectID' ";
    
    objRS = Server.CreateObject("ADODB.Recordset");
    objRS.ActiveConnection = objConn;
    objRS.Open(strSQL);
    
    
    strSubjectID = objRS("uidSubjectID")
    
    Now, when I try to use strSubjectID after the
    objRS.close();

    it sais

    ADODB.Field error '80020009'

    Object is no longer valid.


    ***? How can I reuse it? I need to redirect the person to another page using a query string.

    Response.Redirect(Messages?ID=strSubjectID);
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    pvb
    Guest
    Well i wasn't paying attention at first, wrote a test page with your code using vbscript and it worked like a champ...then i read your code a little closer and it appeared to be jscript so i rewrote the test page and got your error. I got it to work though:
    Code:
    <script language="jscript" runat="server">
    var cn = Server.CreateObject("ADODB.Connection");
    cn.Open("provider=sqloledb;user id=sa;password=sa;database=pubs;server=deathangel;");
    var rs = Server.CreateObject("ADODB.Recordset");
    rs.Open("Select newid() as 'myNewId'", cn);
    var sId = rs("myNewId").value;
    rs.Close();
    cn.Close();
    </script>
    <html>
    <body>
    Your newid() is <%= sId %>
    </body>
    </html>
    Another way would be:
    Code:
    <%@ Language="JScript"%>
    <%
    var cn = Server.CreateObject("ADODB.Connection");
    cn.Open("provider=sqloledb;user id=sa;password=sa;database=pubs;server=deathangel;");
    var rs = Server.CreateObject("ADODB.Recordset");
    rs.Open("Select newid() as 'myNewId'", cn);
    
    
    /*********************************************************/
    var sId = rs("myNewId");	
    /*	passes a reference, not the value, of a field object,
    	to the variable sId. Closing the recordset now would
    	also terminate the reference variable(sId).  So placing
    	the Close() methods of the recordset and connection
    	objects at the end of the whole script would allow the
    	page to use the sId ado field object reference 
    	successfully(so long as you use the "value" property).
    */
    
    
    %>
    <html>
    <body>
    Your newid() is <%= sId.value %>
    </body>
    </html>
    <%
    rs.Close();
    cn.Close();
    %>

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    I must be missing something. Its still not working with .value
    Heres ALL my code, sorry I should of posted it earlier.

    Code:
    <%@ Language=Javascript %>
    <%
    	var strTopicID = Request.Form("txtTopicID");
    	var strSubjectID = "";
    	var strSubject = Request.Form("txtSubject");
    	var strMessage = Request.Form("txtMessage");
    	var intThreads = 0;
    			
    	var objConn;
    	var objRS;
    
    	
    	objConn = Server.CreateObject("ADODB.Connection");
    	objConn.ConnectionString = Application("ConnectionString");
    	objConn.Open();
    	
    	strSQL = "";
    	strSQL += "SELECT NEWID() AS 'uidSubjectID' ";
    
    	objRS = Server.CreateObject("ADODB.Recordset");
    	objRS.ActiveConnection = objConn;
    	objRS.Open(strSQL);
    	
    	strSubjectID = objRS("uidSubjectID")
    
    	strSQL = "";
    	strSQL += "INSERT INTO tblSubjects (uidSubjectID, uidTopicID, vchName) ";
    	strSQL += "VALUES ('" + strSubjectID + "', '" + strTopicID + "', '" + strSubject + "')";
    
    	objConn.Execute(strSQL);
    
    	strSQL = "";
    	strSQL += "INSERT INTO tblMessages (uidSubjectID, vchMessage, vchSubject)";
    	strSQL += "VALUES ('" + strSubjectID + "', '" + strMessage + "','" + strSubject + "')";
    
    	objConn.Execute(strSQL);
    	
    	objRS.Close();
    	
    
    	Response.Write(strSubjectID.value);
    
    %>
    Same error.

    Thanks for the help; I really appriciate it.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  4. #4
    pvb
    Guest
    your code:
    Code:
    strSubjectID = objRS("uidSubjectID")
    correct code:
    Code:
    strSubjectID = objRS("uidSubjectID").value
    just explicitly reference what you want and you should be safe. In vbscript, you don't need to do this(which is good and bad) but apparently in jscript you're required to.

  5. #5
    pvb
    Guest
    oh, and i'm bettin if you reverse the position of the last two lines of your last example(the response.write and recordset.close) that you won't get an error either. once you close the recordset you basically kill any references to the field(the newid part).

  6. #6

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Thumbs up

    Thank you so much guys,
    It works 100%. I was about to break my computer last night

    Thanks Again!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width