Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sparky753
Starting Member
7 Posts |
Posted - 2007-06-05 : 11:29:22
|
I've been trying to figure out how to do this but can't seem to. Here's my scenario:There are 2 related tables: tblEventseventID (PK)eventDateeventNametblEventPresentationseventPresID (PK)EventPresentationNameeventPresentereventIDOne record in tblEvents can have many records in tblEventPresentationsI am trying to write ASP code/SQL queries that would do the following:Display a record from tblEventsThen display all corresponding records in tblEventPresentationsRepeat this for every record in tblEventsFor example:Event1 06-04-07Presentation 1 - Presenter 1Presentation 2 - Presenter 2..Event2 06-06-07Presentation 1 - Presenter 1Presentation 2 - Presenter 2..Right now, this is what my code looks like:<%set RS1 = Server.CreateObject("ADODB.RecordSet")set RS2 = Server.CreateObject("ADODB.RecordSet")sql1 = "Select * from tblEvents"RS1 .Open sql1 , oConnif RS1.EOF then%>...<% else %><% RS1.MoveFirst do while not RS1.EOF Response.Write RS1("eventName") Response.Write RS1("eventDate") %> <% sql2 = "Select * from tblEventPresentations where eventID = " & RS1("eventID") RS2.Open sql2 , oConn RS2.MoveFirst do while not RS2.EOF Response.Write RS2("EventPresentationName") Response.Write RS2("EventPresenter") %> <% RS2.MoveNext loop %> <% RS1.MoveNext loop %> <%end if %>This works fine for the first recordset but gives an error for the subsequent recordsets. What am i doing wrong? Please help!!! |
|
sparky753
Starting Member
7 Posts |
Posted - 2007-06-05 : 13:06:08
|
Never mind, folks! I figured out how to do it. I have to close the recordset in the inner loop - in this case, RS2.Close <%RS2.MoveNextloopRS2.Close%> That fixed it....Thanks |
|
|
|
|
|