Submitting Form to Access Database
December 8, 2005 12:00 AM
Actaul working asp file...need to create both acess dbase called 'Test Results' with table called 'Result' to match field names and ODBC connection on the sever to connect the two.....Neil<%@ Language=VBScript %><%'Get the parameters posted from the test'testname=Request.form("TestName")score=Request.form("Score")name=Request.form("Name")numQuestions=Request.form("NumQuestions")passingGrade=Request.form("PassingGrade")trueFalse=Request.form( "TrueFalse" )multipleChoice=Request.form( "MultipleChoice" )'Validate that this is actually from a Lectora test'if testname="" Or score="" Or name="" Or numQuestions="" Or passingGrade="" Or trueFalse="" Or multipleChoice="" then Response.Write "" Response.Write "Failure " Response.Write "" Response.Write "STATUS=500" Response.Write "
" Response.Write "Could not parse test results due to a parameter error." Response.Write ""else 'Write the results to an access database' ' First let us create Connection and Recordset objects' Set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.RecordSet") ' Open the connection to the ODBC source, in this case the Access database' Conn.Open "TestResults" ' Now, create the SQL statement' sSQL = "INSERT INTO Result(TestName,PassingGrade,NumQuestions,MultipleChoice,Tru eFalse,Name,Score) VALUES ( '" & testname & "', " & passingGrade & ", " & numQuestions & ", " & multipleChoice & ", " & trueFalse & ", '" & name & "', " & score & ")" ' Execute the SQL statement, and set the recordset object' ' to the result of this execution. We obtain the resulting' ' records in Rs object' Set Rs = Conn.Execute(sSQL) ' Close the Recordset object and destroy it' Set Rs = Nothing ' You might want to release the resources for connection object, ' ' unless you want to use the same connection again in the later code' Conn.Close Set Conn = Nothing 'The response is optional, it is good for debugging' Response.Write "" Response.Write "Success " Response.Write "" Response.Write "STATUS=200" Response.Write "
" Response.Write(sSQL) Response.Write "
" Response.Write "Success." Response.Write ""end if%>
Discussions have been disabled for this post