option explicit and getrows (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


yogaboy -> option explicit and getrows (3/26/2005 9:15:28)

Quick quiz...

If I'm using getrows and option explicit, do I need to declare the array I use with the getrows and if so, how am I going to initialize it without knowing how may records will be returned?

The first prize is a small country on Venus. It's nice and warm there.




BeTheBall -> RE: option explicit and getrows (3/26/2005 11:56:50)

Yes, you will get an error if you don't declare the array. As far as "initializing" the array, I am not positive what you mean by that. Generally, you use a For/Next Loop to gather the data from the array. Here is a simply example that displays one field from a table in a one-column, multi-rowed table:

<%option explicit%>
<html>

<head>
<title>Test</title>
<meta name="Microsoft Border" content="tlrb, default">
</head>

<body>
<% 
Dim conntemp, myDSN, myRS, mySQL, arrTable, nRows, row, col
Set conntemp=Server.CreateObject("ADODB.Connection") 
myDSN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/Review304.mdb") 
conntemp.open myDSN  
mySQL = "SELECT IDRS, [Name] FROM Employees"
Set myRS = Server.CreateObject("ADODB.Recordset") 
myRS.Open mySQL, conntemp, 0, 1
arrTable=myRS.GetRows()
myRS.Close 
Set myRS = nothing 
conntemp.Close 
Set conntemp = nothing 
%>
<TABLE BORDER=1>
    <% 
    nRows = UBound(arrTable, 2 )
    For row = 0 To nRows 
    %>
    <TR>
    <% 
    For col = 0 To UBound(arrTable, 1 ) 
    %> 
    <TD><%=arrTable(col, row)%>  </TD>
    <% Next %>
    </TR>
    <% Next %>
    </TABLE>

<p>  </body>

</html>





yogaboy -> RE: option explicit and getrows (3/26/2005 12:06:14)

Thanks!

By initializing the array I meant that normally with an array if you declare it without specifying the upper bound then you need to initialize it by using ReDim,

Dim myArray()
ReDim myArray(5)

but I see that's not needed in the code you gave. Thanks again Duane, really helpful stuff.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875