473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How This Code Works

I want an ASP app to retrieve records from a MS-Access database table
but display them in a HTML table but I want the HTML table table to
display only 7 records in a row (<tr>...</tr>) in 7 different cells
(<td>...</td>). In other words, if there are 14 records in the DB
table, the HTML table should display the 14 records in 2 rows - the
1st row displaying the 1st 7 records from the DB table & the 2nd row
displaying the remaining 7 records existing in the DB table. This is
how I did it:

------------------------------------------------
<%
On Error Resume Next

Dim objConn
objConn=Server.CreateObject("ADODB.CONNECTION")
'open the connection using ConnectionString

Dim strSQL
strSQL="SELECT * FROM MyTable ORDER BY Col1"

Dim objRS
Set objRS=Server.CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Dim iCount
%>
<table border=1>
<%
Do Until(objRS.EOF)
%>
<tr>
<%
For iCount=iCount To iCount+6
%>
<td><%= objRS("Col1") %></td>
<%
objRS.MoveNext
Next
%>
</tr>
<%
Loop
%>
</table>
------------------------------------------------

The above code does display the records how I want to display but to
be honest, I couldn't exactly understand the logic of the above code.
Can someone please explain me the logic behind the above code?

Also note the On Error Resume Next line. Though the above code
displays the records exactly how I want them to be displayed in the
HTML table, if I comment the On Error Resume Next line, then ASP
generates the

Exception occured.

error without pointing to any line. I know what's causing the error
but can't find a way out to overcome the error. Can someone please
help me resolve this error as well?

Thanks.

Apr 11 '07 #1
1 1623
rn**@rediffmail.com wrote on 11 Apr 2007 14:05:32 -0700:
I want an ASP app to retrieve records from a MS-Access database table
but display them in a HTML table but I want the HTML table table to
display only 7 records in a row (<tr>...</tr>) in 7 different cells
(<td>...</td>). In other words, if there are 14 records in the DB
table, the HTML table should display the 14 records in 2 rows - the
1st row displaying the 1st 7 records from the DB table & the 2nd row
displaying the remaining 7 records existing in the DB table. This is
how I did it:

------------------------------------------------
<%
On Error Resume Next

Dim objConn
objConn=Server.CreateObject("ADODB.CONNECTION")
'open the connection using ConnectionString

Dim strSQL
strSQL="SELECT * FROM MyTable ORDER BY Col1"

Dim objRS
Set objRS=Server.CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Dim iCount
%>
<table border=1>
<%
Do Until(objRS.EOF)
%>
<tr>
<%
For iCount=iCount To iCount+6
%>
<td><%= objRS("Col1") %></td>
<%
objRS.MoveNext
Next
%>
</tr>
<%
Loop
%>
</table>
------------------------------------------------

The above code does display the records how I want to display but to
be honest, I couldn't exactly understand the logic of the above code.
Can someone please explain me the logic behind the above code?
It's pretty simple - get the results, and for every 7 rows in the recordset
write them out in TD tags. First time round the For Next loop iCount will
increment from 0 to 6, second time round from 7 to 13, etc. although the
value of iCount is meaningless - it could just as easily have been "For
iCount = 1 To 7" and it would do the same job.

Also note the On Error Resume Next line. Though the above code
displays the records exactly how I want them to be displayed in the
HTML table, if I comment the On Error Resume Next line, then ASP
generates the

Exception occured.

error without pointing to any line. I know what's causing the error
but can't find a way out to overcome the error. Can someone please
help me resolve this error as well?
If the number of rows in the result is less than a multiplication of 7 (ie.
7, 14, 21, etc) then the MoveNext will cause an error because there is no
checking for EOF in the For Next loop. The On Error Resume Next disguises
this, and allows the creation of empty cells by simply ignoring the error
caused by = objRS("Col1") when the recordset has passed the last row, and
subsequently by the MoveNext because the recordset is already past the last
row so there is no row to move to. The following edit should handle this
without the need for the On Error statement

<%
Dim objConn
objConn=Server.CreateObject("ADODB.CONNECTION")
'open the connection using ConnectionString

Dim strSQL
strSQL="SELECT * FROM MyTable ORDER BY Col1"

Dim objRS
Set objRS=Server.CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Dim iCount
%>
<table border=1>
<%
Do Until(objRS.EOF)
%>
<tr>
<%
For iCount=iCount To iCount+6
%>
<td>
<%
If Not objRS.EOF Then
Response.Write objRS("Col1")
objRS.MoveNext
End If
%>
</td>
<%
Next
%>
</tr>
<%
Loop

%>
</table>

Dan
Apr 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
192
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
2
by: John | last post by:
I am having a weird error and maybe the synatax is different or something. I use a SQL Stored Proc and pass it one param and get a return to either a datareader or dataset. The code works fine for...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
1
by: Alex Clark | last post by:
Hi all, Apologies for the cross-post but I can't determine if this is a VS .NET problem or a VB.NET language issue. I'm using .NET 1.1 SP1, VS 2003 EA, VB.NET. I'm coding a custom component...
64
by: Bayazee | last post by:
hi can we hide a python code ? if i want to write a commercial software can i hide my source code from users access ? we can conver it to pyc but this file can decompiled ... so ...!! do you...
2
by: electroman | last post by:
Hello! I am having a very weird problem that I cant find any solution on the Internet (after so many years!). I am trying to code a C# program and I am using the WebBroswer control. The code is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.