Connecting Tech Pros Worldwide Help | Site Map

ASP Classic Loop

Newbie
 
Join Date: Aug 2008
Location: Orlando, FL
Posts: 13
#1: Mar 4 '09
I'm trying to create one landingpage for several different clients that the page recognizes what client is coming to the page and displays the proper services in the table I've created. The only problem is that I can't get the header of the table to update to what I have in the database. The name of the field in my SQL2005 DB is called IsPckgHeader.

< %
Dim conn
Set conn = server.createobject("ADODB.Connection")
conn.connectionstring = "provider=******.1;password=******;persist security info=true;user id=*****;initial catalog=******;data source=*****;"
conn.open

Dim iClntID : iClntID = request("clntID")

Dim strReturn
strReturn = "Select * from Svcs where ClntID = " & iClntID


Dim SvcDesc
Dim Price
Dim rsRecordSet
Set rsRecordSet = conn.execute(strReturn)



do while not rsRecordSet.EOF

SvcDesc = rsRecordSet("SvcDesc")
Price = rsRecordSet("Price")

if isNull(Price) then
Price = ""
else
Price = formatCurrency(Price)
end if


% >
<tr>
<td style="Border-Style: Solid; Border-Width: 1px; Border-Color: #000000" width="80%" bgcolor="#EBEBEB"><font size="2"><% response.write(SvcDesc) %> </font></td>
<td style="Border-Style: Solid; Border-Width: 1px; Border-Color: #000000" width="80%" bgcolor="#EBEBEB"><font size="2"><% response.write(Price) %></font></td>
</tr>
< %
rsRecordSet.movenext
loop

conn.close
% >


Also if someone can help me create mutiple tables that would help tremendously. Thank you.
jenkinsloveschicken's Avatar
Member
 
Join Date: Dec 2006
Posts: 56
#2: Mar 4 '09

re: ASP Classic Loop


Stryker,

You mention not being able to get the header of your table to update. I don't see you writing out <th> anchors at all, so I'm assuming your in-line response.writes are not sending the correct values to the HTML markup.

Not on a machine with IIS to test but, this should work:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <td style="Border-Style: Solid; Border-Width: 1px; Border-Color: #000000" width="80%" bgcolor="#EBEBEB"><font size="2"><% response.write SvcDesc %> </font></td>
  3.  
  4.  
As long as the SvcDesc variable is not null. It won't produce an error, but obviously won't update the HTML.

It's fairly easy to create multiple tables. If you are wanting to do it in the loop, then you need to define at what point in the loop you are needing a new table. Or you can build it after the loop. If you need multiple tables inside the loop, then I would actually define the cursor type and lock type as opposed to using conn.execute(In general, I only use conn.execute for DML-inserts/updates/deletes, since you aren't expecting any records to return), such as adOpenStatic, and adLockReadOnly. Reason being is that this cursor/lock type supports the recordCount property. So instead of doing a "Do While" loop, you could loop from 1 To myUboundValue(which would be your recordcount value) and tell the code to build a new table at one of the increments( in other words, if you have 10 records returned, you would move from 0 To 9. In the code of the loop, you can tell it create a new table at a specific point in the recordset loop.

Hope this helps. Reply with some information on what you are trying to accomplish with multiple tables so we can get a better idea of the solution you need.

Best Regards,
Jenkins
Reply

Tags
asp, asp classic, classic, loop, table