dcsimg
Problem with while and resultsets
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Code_Chimp
Posted On:   Tuesday, May 6, 2003 11:51 AM

I have the following code: <% cpartner.connect(); ResultSet rsPartner = cpartner.getPartner(); ResultSet rsPartnerCategories = cpartner.getPartnerCategories(); while (rsPartnerCategories.next()) { %> <%= rsPartnerCategories.getString("PartnerCategoryName") %> <% while (rsPartner.next()) { %> <%= rsPartnerCategories.getString("PartnerCategoryName") %>| <%= rsPartner.getString("PartnerCategoryName") %>| <%= rsPartner.getString("PartnerName") % <% } } %> I was expecting to have the outer whi   More>>

I have the following code:
<%
cpartner.connect();
ResultSet rsPartner = cpartner.getPartner();
ResultSet rsPartnerCategories = cpartner.getPartnerCategories();
while (rsPartnerCategories.next())
{
%>

<%= rsPartnerCategories.getString("PartnerCategoryName") %>

<%
while (rsPartner.next())
{
%>


<%= rsPartnerCategories.getString("PartnerCategoryName") %>| <%= rsPartner.getString("PartnerCategoryName") %>| <%= rsPartner.getString("PartnerName") %



<%
}
}
%>

I was expecting to have the outer while spit out the results (of which there are three) and within each of those results have the inner while spit out six results.

Instead I get:
OuterLoopItem1
- InnerLoopItem1
- InnerLoopItem2
- InnerLoopItem..
- InnerLoopItem6
OuterLoopItem2
OuterLoopItem3

The InnerLoop result set has multiple columns so a list will not be enough.

Can anyone help please?

   <<Less

Re: Problem with while and resultsets

Posted By:   Anonymous  
Posted On:   Sunday, May 11, 2003 11:50 PM

Hi Code,


I think that you may be getting an error as you are trying to read the same column twice( Line A and Line B in the following code).



<% cpartner.connect();
ResultSet rsPartner = cpartner.getPartner();
ResultSet rsPartnerCategories = cpartner.getPartnerCategories();
while (rsPartnerCategories.next()) { %>
<%= rsPartnerCategories.getString("PartnerCategoryName") %> // line A
<% while (rsPartner.next()) { %>
<%= rsPartnerCategories.getString("PartnerCategoryName") %> // line B
<%= rsPartner.getString("PartnerCategoryName") %>
<%= rsPartner.getString("PartnerName") %

Here is the reason(from the ResulSet API):


ResultSet columns within each row should be read in left-to-right order, and each column should be read only once.


Removing Line A or Line B should fix your problem.


Please use 'pre' tags for the code you put in the page. This would make your code readable(formatted).
About | Sitemap | Contact