View Full Version : Pulling Questions for a form from a db
fishbone34
05-25-2006, 04:14 PM
Hello, I have a asp web form that have 10-14 questions. It seems to be getting more and more freq that people want to change the wording on the form. What I would like to do is build a db table and pull the questions from the DB. This way is they want to "reword" the question, All I have to do is change the db row.
I have set up a Table called questions:
id QTYPE QSUBTYPE QNUMB QUESTION
1 SO Q 1 Question wording 1
2 SO Q 2 Question 2 wording.
3 SO Q 3 Question 3 wording.
How can I set an object so I can reference it in my code?
I was thinking something like below.
set objRS=Conn.execute(query3)
Q1 = objRS("1")
Q2 = objRS("2")
Q3 = objRS("3")
and then adding something like this to my page:
<%=Q1%>
BarrMan
05-25-2006, 05:37 PM
Inserting a new question:
Con.Execute "INSERT INTO Questions (Question,type,type2) VALUES ('" & request.form("question") & "'," & type & "," & type2 & ")"
Updating a question:
Con.Execute "UPDATE Questions SET Question='" & request.form("question") "' WHERE Qid=" & request.form("qid")
Hope that helped.
fishbone34
05-25-2006, 07:43 PM
Thank's Barrman. But unfortunatly, that's not what I meant.
What I meant is that I have a table with a list of questions.
I want to populate a web(asp) form from the questions in the table. This way if the wording for the questions change, all I need to do is update the table and not the asp page.
Does this make sense?
Chris
ghell
05-26-2006, 04:06 PM
You need to use an ADODB.Connection, make an ADODB.Recordset from an objConn.Execute("..sql..")
and then you probably want a GetRows() to populate a 2D array with your data.
Most people would just use a
Do While NOT rs.EOF
...
rs.MoveNext
Loop
but this is bad practice and GetRows() is prefered. (GetString() is even better but its not as flexible)
http://www.w3schools.com/ado/showasp.asp?filename=demo_ado_getrows
Ideal code would use the following layout:
Dim objConn, rsQuestions, arrQuestions
' Fill the 2D array with the questions list, then close all objects and destroy them
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("...")
Set rsQuestions = objConn.Execute("...")
If NOT rsQuestions.EOF Then arrQuestions = rsQuestions.GetRows()
Set rsQuestions = Nothing
objConn.Close()
Set objConn = Nothing
' Display the results
If IsArray(arrQuestions) Then
For iRecord = LBound(arrQuestions, 2) To UBound(arrQuestions, 2)
Response.Write arrQuestions(0, iRecord) & "<br />"
Next
Else
Response.Write "No Questions Found"
End If
degsy
05-31-2006, 03:39 PM
Here are examples on how to output database records to update them
http://www.w3schools.com/ado/ado_update.asp
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.