I'm a student learning ASP. I'm facing a slight problem affecting
my "learning curve". I am using two recordset to retrieve info from two
different tables (from an Access DB). I am displaying students records
from first recordset and then each student records has a Sentence field
with drop down list with some values coming from the other recordset. I
need to update the dropdown menu using the Sentence information coming
from the second recordset. When student info is retrieved, there should be
a drop down field for sentence that should be used to assign sentences
(from drop down list) to students. How can I link the dropdown object to
the entries in the database? By the way, I've been able to display the
dropdown list but cannot populate it. I looked through many questions that
are already answered on this website and tried them but nothing is
working!! Now I need professional help in getting over it. Following is
the code that I've written so far:
Hamid
ASP code starts here-------------------------->
<html>
<head>
<title>Minnesota State University, Mankato - COMS 462 - Data
Communications and Networking I</title>
</head>
<body bgcolor="#FFFFFF">
<%
Function RecToTable (objRec, obj1Rec)
Dim strT ' table html string
Dim fldF ' current field object
Dim fldF1 ' current field object
counter = 0
m = 0
'While Not objRec.EOF
' build the table header
strT = "<TABLE BORDER=1><TR ALIGN=CENTER>"
j = 0
' each field as a table column name
For Each fldF In objRec.Fields
'If student info is complete, add a drop down field for sentence that
should be assigned to atudents, using a dropdown list
if j = 3 then
strT = strT & "<TD>Sentence Selection</TD>"
k = j
j = 0
else
strT = strT & "<TD>" & fldF.Name & "</TD>"
j = j + 1
end if
Next
strT = strT & "</TR>"
i = 1
' now build the rows
While Not objRec.EOF
strT = strT & "<TR ALIGN=CENTER>"
' add the fields
For Each fldF in objRec.Fields
if j = k then
' Here I'm trying to populate the drop down list within the first recordset
While Not obj1Rec.EOF
counter = counter + 1
obj1Rec.MoveNext
wend
obj1Rec.MoveFirst
strT = strT & "<td><SELECT SIZE =" & counter & " NAME=Field></td>"
While Not obj1Rec.EOF
strT = strT & "<option value='" & obj1Rec("Sentence") & ">" &
obj1Rec("Sentence") & "</option>"
obj1Rec.MoveNext
m = m + 1
wend
j = 0
else
strT = strT & "<TD>" & fldF.Value& "</TD>"
j = j+1
end if
Next
strT = strT & "</TR>"
objRec.MoveNext
i = i+1
Wend
strT = strT & "</TABLE>"
' and finally return the table
Response.Write(i)
Response.Write"<br>" & (j) & "<br>" & (counter) & "<br>" & (m)
RecToTable = strT
End Function
%>
<%
'Varible Declarations
Dim strSQL 'SQL String
Dim str1SQL 'SQL String
Dim objRec 'Recordset Object
Dim obj1Rec 'Recordset Object
Dim objField 'Field Object
'Connection to the database
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
("463test.mdb")
SET objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strconn
'SQL Statement: Get the info about students and sentence to be assigned to
students in two record sets
'Get student records
strSQL = "SELECT UserName, TechId, FName, LName " &_
"FROM Student"
'Get sentence records
str1SQL = "SELECT Distinct Sentence FROM Input_Sentence"
'Opens the connection to the server and sends the sql statement
'to the database
SET objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, objConn
SET obj1Rec = Server.CreateObject("ADODB.Recordset")
obj1Rec.Open str1SQL, objConn
' write a table of the recordset
Response.Write RecToTable (objRec, obj1Rec)
%>
</body>
</html>