954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP electronic exam project, problem when update data base

Computer Network Exam

<%
if request("do")="next" then
i=request("i")
i=i+1


elseif request("do")="pervious" then
i=request("i")
i=i-1


else
i=2
end if


selectSQL="select * from question "

Dim oRecordset
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 'adUseClientrs.CursorLocation = 3 ' adUseClient
rs.pagesize=1

rs.open selectSQL,ado

if cint(i)>rs.pagecount+1 then
'update_Answer()
response.write "end of questions.............." & rs.pagecount &"?"
response.redirect("result.asp")
end if
rs.AbsolutePage=i-1

if cint(i)<2 then

response.redirect ("exam2.asp")
end if
if NOT rs.EOF then
%>

<%=rs.FIELDS("Question").VALUE%>



<%=rs.FIELDS("Q_ID").VALUE%>
name="m">
 Q

<%=rs.FIELDS("a").VALUE%>

a
<%=rs.FIELDS("b").VALUE%>

b
<%=rs.FIELDS("c").VALUE%>

c
<%=rs.FIELDS("d").VALUE%>

d




" style="float: left">mark




<%
update_Answer()
%>

<%
if request("do")="review" then
response.redirect("review.asp")
end if
%>

<%
if request("do")="end" then
response.redirect ("result.asp")
end if
%>

<%
end if
%>


name="i">
  






name="i">  


 




<% update_Answer()%>


<%
Sub update_Answer()
r=request("radio")

'Initialise the strSQL variable with an SQL statement to query the database

strSQL = "SELECT answer.* FROM answer WHERE Q_ID="&(rs.FIELDS("Q_ID").VALUE-1)
'Reset server objects
rs.Close
Set rs = Nothing
Set rs = Server.CreateObject("ADODB.Recordset")

'Set the cursor type we are using so we can navigate through the recordset
rs.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rs.LockType = 3

'Open the recordset with the SQL query
rs.Open strSQL, ado

'Update the record in the recordset

rs.Fields("user_answer")=cint®
'Write the updated recordset to the database
rs.Update
'Reset server objects
rs.Close
Set rs = Nothing
Set adoCon = Nothing
End Sub
%>

Attachments exam.txt (6.72KB) Connection.txt (0.48KB)
eng.nema
Newbie Poster
7 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

I'm not going to study your code in detail, but I did look at the getRadioValue function.

The one thing that occurred to me was that if no radio element had been checked (which is quite often the case when a form is first loaded), then the "var answer = radioObject[i].value;" statement would not have been executed. Thus, the "answer" variable would not have been defined.

Is it possible that this caused your error?

Hoppy

hopalongcassidy
Junior Poster
148 posts since Oct 2007
Reputation Points: 53
Solved Threads: 13
 

Thank you very much ; hopalongcassidy
you are right and my problem solved

Thank you again

eng.nema
Newbie Poster
7 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You