Evaluating form elements

Results 1 to 2 of 2

Thread: Evaluating form elements

  1. #1
    Jay D Guest

    Default Evaluating form elements

    I have an on-line quiz I am working on. For each form item I am querying a database to see if the response is correct. Problem is the Stored Procedure is expecting a question number and their are other form items such as Submit1, Count, etc that do not correspond to question numbers. <BR><BR>ASP code:<BR>***************************************** ***********************<BR><BR>for each item in Request.Form<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>Create Parameters<BR>.Parameters.Append objCmd.CreateParameter("@c_id", adInteger, 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>Next<BR>percent = round(( 100 * result )/count)<BR><BR>Here is the stored procedure:<BR>************************************ ****************************<BR><BR>CREATE PROCEDURE CheckAnswers_SP<BR>@c_id int,<BR>@question_number int,<BR>@correct_answer varchar<BR><BR> AS<BR>SET NOCOUNT ON<BR>DECLARE @tblName nvarchar (25)<BR><BR>SET @tblName = (SELECT Tbl_Name <BR> FROM tblCourse <BR> WHERE (c_id = @c_id))<BR><BR>DECLARE @mySQL nvarchar(1000)<BR>SET @mySQL = &#039SELECT COUNT(*)&#039<BR>SET @mySQL = @mySQL + &#039 FROM &#039 + @tblName<BR>SET @mySQL = @mySQL + &#039 WHERE question_number = &#039 + Convert(nvarchar(4), @question_number) <BR>SET @mySQL = @mySQL + &#039 AND correct_answer = "&#039 + @correct_answer +&#039"&#039<BR><BR>EXEC(@mySQL)<BR><BR>PRINT(@myS QL)<BR>SET NOCOUNT OFF<BR><BR>*************************<BR><BR>The stored procedure works fine in query analyzer. The problem is the items in the form. Look at this response write of the elements in my form:<BR><BR>1 Value = d <BR>2 Value = c <BR>submit1 Value = Submit #!!! This one causes a problem! <BR>4 Value = a <BR>5 Value = c <BR>6 Value = b <BR>114 Value = c <BR>7 Value = b <BR>12 Value = b <BR>115 Value = b <BR>13 Value = c <BR>113 Value = b <BR>14 Value = b <BR>count Value = 116 #!!!! This one causes a problem.<BR><BR>My question is how to only check the items with numbers?<BR><BR>Jay<BR><BR><BR><BR>

  2. #2
    Jay D Guest

    Default RE: Evaluating form elements

    I&#039ve figured out one way to do it by using this<BR><BR>If IsNumeric(item) Then<BR> Process my code<BR><BR>There&#039s gotta be a more efficient way to process this answer checking than 115 recordset&#039s... I just haven&#039t figured it out yet. <BR><BR>Any suggestions?<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