Sign in to follow this  

[web] ASP Random Item

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A friend recommended me to this site as being really helpful so I thought I'd come to you guys with a question in regards to generating a page in ASP that randomly selects an item from a database and displays it on the page. I have all the code working save for the random generation of the ItemID number. Here's what the chunk of code looks like for my SQL query:
   strSQL = "SELECT Items.ItemID, Items.ItemName, Items.ItemType, Items.ItemPriceBuy, Vendors.VendorName " & _
            "FROM Items INNER JOIN Vendors ON Items.VendorID = Vendors.VendorID " & _
            "WHERE ItemID = intItemID;"
And to generate the random number that the variable intItemID is, I've used the following code:
   randomize
   intItemID = Int(22* rnd(1)) +1
When using the combination of the code, I receive the following error:
Quote:
Microsoft OLE DB Provider for ODBC Drivers error '80040e10' [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. ../RandomItem.asp, line 25
If anyone has any idea as to how I might fix this issue, it would be greatly appreciated, thanks!

Share this post


Link to post
Share on other sites
You are using Microsoft Access right? Can't you assign the itemID field as a automajickally created number? AutoNumber or some such like that? Or do you need the value to be completely random...?

And second... what does line 25 look like? From the error message, it would appear that you are calling some function/sub that requires at least one parameter to function correctly. Can you show us the area of code around the line 25?

Share this post


Link to post
Share on other sites
Quote:
Original post by fraKtal
You are using Microsoft Access right? Can't you assign the itemID field as a automajickally created number? AutoNumber or some such like that? Or do you need the value to be completely random...?

And second... what does line 25 look like? From the error message, it would appear that you are calling some function/sub that requires at least one parameter to function correctly. Can you show us the area of code around the line 25?

I suppose the whole script is short enough so that I can post it in its entirty, maybe it will help the situation:

<%
dim objRS, strSQL, intItemID

randomize
intItemID = Int(22* rnd(1)) +1

strSQL = "SELECT Items.ItemID, Items.ItemName, Items.ItemType, Items.ItemPriceBuy, Vendors.VendorName " & _
"FROM Items INNER JOIN Vendors ON Items.VendorID = Vendors.VendorID " & _
"WHERE ItemID = intItemID;"

response.write strSQL

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn
%>


AutoNumber is generated, what I'm trying to do is to create a page that randomly selects one of the 22 items in the item table database and display it.

Share this post


Link to post
Share on other sites

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this