response.write querying 2 tables

Results 1 to 2 of 2

Thread: response.write querying 2 tables

  1. #1
    Wizzzard Guest

    Default response.write querying 2 tables

    Hi, I am having major problems when the with a reletivly simple peice of code, I have two tables one for questions and another for the answers which will be multiple choice , therefore each question will have 2 or more answers, so to test this I am trying to print out the question with the relevant set of answers in a table. The problem I am having is testing the answer with the question, the relation is where they both have the same question ID..... <BR><BR>Here is the error message:<BR>ADODB.Recordset (0x800A0CC1)<BR>Item cannot be found in the collection corresponding to the requested name or ordinal.<BR><BR>I have tested different ways,the problem is in this line:<BR>oRSQuestions("quest_id").value = oRSanswers("quest_id").value<BR><BR><BR>Please can someone look at my code to see if they know where I am going wrong, i would really appreciate any suggestions.<BR><BR>&#060;%<BR>set oRSanswers = Server.CreateObject("ADODB.Recordset")<BR>oRSanswe rs.ActiveConnection = "driver={SQL Server)**"<BR> oRSanswers.CursorType = 1<BR> oRSanswers.CursorLocation = 1<BR> oRSanswers.LockType = 1<BR> oRSanswers_numRows = 0<BR>set oRSQuestions = Server.CreateObject("ADODB.Recordset")<BR> oRSQuestions.ActiveConnection = "driver={SQL Server}**"<BR> oRSQuestions.CursorType = 1<BR> oRSQuestions.CursorLocation = 1<BR> oRSQuestions.LockType = 1<BR> oRSQuestions_numRows = 0<BR> oRSQuestions.source = "SELECT question FROM QUESTIONS ORDER BY QUEST_ID"<BR> oRSanswers.source = "SELECT answer FROM ANSWERS ORDER BY QUEST_ID"<BR> oRSQuestions.Open<BR> oRSanswers.Open<BR><BR>do while not oRSQuestions.EOF<BR> response.write"&#060;tr&#062;"<BR> response.write"&#060;td&#062;"& oRSQuestions("question") &"&#060;/td&#062;"<BR><BR> do while NOT oRSanswers.EOF AND oRSQuestions("quest_id").value = oRSanswers("quest_id").value<BR><BR> response.write"&#060;td&#062;"& oRSanswers("answer")&"&#060;/td&#062;"<BR><BR> oRSanswers.movenext<BR><BR> loop<BR> response.write"&#060;/TR&#062;"<BR> oRSQuestions.movenext<BR> loop<BR><BR> oRSanswers.close<BR> oRSQuestions.close<BR> set oRSanswers = nothing<BR> set oRSQuestions = nothing<BR><BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default Do NOT use two tables!<BR><BR>You *can* use two tables, but why work so hard for something as simple as this?<BR><BR>The problem your code is having, if you care, is that unlike C and C++ and Java and JS, VBS *always* executes the code in EACH piece of an AND or OR condition. So even though you are at the EOF on one or both of the recordsets, the clause you noted is *STILL* executing...and since you are at EOF, of course you get the error it shows!<BR><BR>If you *must* code it with two RecordSets (and why?) then you could do:<BR><BR>Do While NOT oRSanswers.EOF <BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; oRSanswers.MoveNext<BR>&nbsp; &nbsp; If oRSQuestions("quest_id") &#060;&#062; oRSanswers("quest_id") Then Exit Do<BR>Loop<BR><BR>or some variation on that theme.<BR><BR><BR>

Posting Permissions

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