VBScript UBound shows 0 ??

Hello,

I'm having issues with Ubound...

It is returning 3, when there are only 2 records in the database...

The VBScript reads like this --

<%
dim bannercount

Dim cmdbanner__Brand
cmdbanner__Brand = NULL
if(Request("Brand") <> "") then cmdbanner__Brand = Request("Brand")

set cmdbanner = Server.CreateObject("ADODB.Command")
cmdbanner.ActiveConnection = MM_GolfConnection_STRING
cmdbanner.CommandText = "dbo.PriceGuideBannerDisplay"
cmdbanner.CommandType = 4
cmdbanner.CommandTimeout = 0
cmdbanner.Prepared = true
cmdbanner.Parameters.Append cmdbanner.CreateParameter("@RETURN_VALUE", 3, 4)
cmdbanner.Parameters.Append cmdbanner.CreateParameter("@Brand", 3, 1,4,cmdbanner__Brand)
set RsBanners = cmdbanner.Execute
RsBanners_numRows = 0

If not RsBanners.eof then
arrBanners = RsBanners.GetRows()
bannercount = UBound(arrBanners)
End if 

RsBanners.Close() 'Clean Up
Set RsBanners = Nothing 'Clean Up
Set cmdbanner = Nothing 'Clean Up
%>

Open in new window


And the database Query is like so --

CREATE PROCEDURE [dbo].[PriceGuideBannerDisplay]
(
@Brand int
)
AS
BEGIN
SET NOCOUNT ON;
IF @Brand IS NOT NULL
BEGIN
SELECT [ID], [Brand], [Filename], [ShowOnHome] FROM [dbo].[PriceGuideBanner] Where Brand = @Brand
END
ELSE
BEGIN
SELECT [ID], [Brand], [Filename], [ShowOnHome] FROM [dbo].[PriceGuideBanner] Where ShowOnHome = 'Y'
END
END

GO

Open in new window


I'm sending no Brand parameter, so the results should be the two records on the database that have ShowOnHome = 'Y'

So surely, bannercount should be 1?

Help!!!

Thanks
garethtnashAsked:
Who is Participating?
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
bannercount = UBound(arrBanners,2)
0
 
Ken ButtersCommented:
Check the values you are getting in your result set.

Which rows from the DB are being returned?  that might help give you a clue as to what's happening.
0
 
garethtnashAuthor Commented:
2 rows, 4 columns...

rows with ID 5 & 8

Very confused?

UBound does count rows?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
garethtnashAuthor Commented:
Thank you
0
 
Ken ButtersCommented:
Looks like getRows returns a 2 dimensional Array.

It looks like you are getting the UBound of the number of columns.  4 columns with a starting array index of zero... gives you the 3 you are getting.

try UBound(arrBanners,2) :  In order to get the Ubound of the 2nd dimension of the array, which should be the number of rows.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
To keep things easy, in my for next loop, I assign variables instead of trying to keep track of which row and column I am on for accessing the array.  Using code like below, you can use a variable inside of a for next loop.

for r = LBound(arrBanners, 2) To UBound(arrBanners, 2)
    	ID= arrBanners(0, r)
	Brand = arrBanners(1, r)
	FileName = arrBanners(2, r)
	ShowOnHome = arrBanners(3, r)


      response.write "Brand= "&Brand&"<br>"
next

Open in new window

0
 
garethtnashAuthor Commented:
that's neat - thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.