Got to be a better way (Recursive)

Results 1 to 4 of 4

Thread: Got to be a better way (Recursive)

  1. #1
    Jay D Guest

    Default Got to be a better way (Recursive)

    Hi folks,<BR><BR>I have a form that is submitted with 118 items. For each item in the collection I want to compare the answer result to the correct answers in a database. The code I have works fine but I am looking for a faster, more efficient method. As it is now, I am making 118 calls to the db.<BR><BR>Am I looking to place the contents of the entire recordset into an array and then loop to compare each answer or what?<BR><BR>I have the following script:<BR><BR>For Each item in Request.Form<BR><BR> If IsNumeric(item) Then<BR><BR> Set rsCheckAnswer = Server.CreateObject("ADODB.RecordSet")<BR> Set objCmd = Server.CreateObject("ADODB.Command")<BR> With objCmd<BR> .ActiveConnection = objConn<BR> .CommandType = adCmdStoredProc<BR> .CommandText = "CheckAnswers_SP"<BR> .Parameters.Append objCmd.CreateParameter("@c_id, adInteger,<BR>adParamInput, 4, Request.QueryString("cid"))<BR> .Parameters.Append objCmd.CreateParameter("@question_number, adInteger, adParamInput, 4, (item))<BR> .Parameters.Append objCmd.CreateParameter("@correct_answer, adChar, adParamInput, 1, Request.Form(item))<BR> End With<BR>set rsCheckAnswer = objCmd.Execute<BR><BR> if rsCheckAnswer(0) &#062; 0 then<BR> result = result + 1<BR> end if<BR><BR>rsCheckAnswer.Close<BR>Set rsCheckAnswer = Nothing<BR><BR>End If<BR><BR>Next<BR><BR>**************************** *********<BR>The stored procedure this is calling simply takes the course id, question number and answer and does a Count * from tbl where question_number = @question_number and correct_answer = @correct_answer.<BR>

  2. #2
    Steve Cimino Guest

    Default RE: Got to be a better way (Recursive)

    Place your answers before hand in an array. Then, check the form items against the array elements. You should see a significant performance increase.

  3. #3
    Richard A. Lowe Guest

    Default RE: Got to be a better way (Recursive)

    Yes, put the form in an array, but also, making all those calls is going to slow you down. A better scheme might be to return every question/answer pair in ONE disconnected recordset and then compare to that recordset. <BR><BR>But that many trips to the db will slow you down.<BR><BR>Richard

  4. #4
    Richard A. Lowe Guest

    Default BTW...

    ... I didn&#039t really see anything recursive about your solution. Recursion usually refers to an entity&#039s (function, method, sub) call to iteself. Just being pedantic... never mind.<BR><BR>Richard

Posting Permissions

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