# [web] ASP Random Item

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

## 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 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 on other sites
Quote:
 Original post by fraKtalYou 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.

1. 1
2. 2
Rutin
26
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631763
• Total Posts
3002197
×