ASP SQL String error

L

Larry_Milner

I'm, trying to generate a random number to be used in a DB lookup of wav
files that can be used as BG sound bytes.

I'm missing something along the STRSQL = line that's blocking me.

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "SELECT WavName FROM "]'
/random_number.asp, line 21

The number generates correctly and the field being selected is the primary
index and an integer (autonumber).

I generate an SQL pull that will work correctly with DATABASE results
wizzard, but not with a random number.

Can anyone see a problem in my syntax?
___________________

<%
Dim intLB
Dim intUB
Dim intRange
Dim sngRanVal
Dim intRanInt

Dim DSN_Name
DSN_Name = Application("Web_ConnectionString")
set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open DSN_Name
Set RS = Server.CreateObject("ADODB.Recordset")

intLB = 1
intUB = 30
Randomize()
intRange = intUB - intLB + 1
sngRanVal = intRange * Rnd()
sngRanVal = sngRanVal + intLB
intRanInt = Int(sngRanVal)

strSql = "SELECT WavName FROM WavTable WHERE ( ID = ::'" + intRanInt + "
::)"'"
RS.Open strSql, Connection

Dim SNDFile
SNDFile = rs("wavename")

RS.close
Connection.close
%>

<html>

<head>
<title>Random BG Sound</title>
<bgsound src ="sounds/wavtable/<%=SNDFile%>">

</head>

</body>

</html>
_____________________________________
 
L

Larry_Milner

Modified it a bit and now the Integer value ::9:: is showing but I'm still
getting and error

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
query expression 'ID = ::9::'.
/random_number.asp, line 22
_________________________________

<%
Dim intLB
Dim intUB
Dim intRange
Dim sngRanVal
Dim intRanInt

Dim DSN_Name
DSN_Name = Application("Web_ConnectionString")
set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open DSN_Name
Set RS = Server.CreateObject("ADODB.Recordset")

intLB = 1
intUB = 30
Randomize()
intRange = intUB - intLB + 1
sngRanVal = intRange * Rnd()
sngRanVal = sngRanVal + intLB
intRanInt = Int(sngRanVal)
strSql = "SELECT WavName FROM WavTable WHERE ID = ::" & intRanInt & "::"'"
RS.Open strSql, Connection

Dim SNDFile
SNDFile = rs("wavename")

RS.close
Connection.close
%>

<html>

<head>
<title>Random BG Sound</title>
<bgsound src ="sounds/wavtable/<%=SNDFile%>">

</head>

</body>

</html>

___________________________________
 
G

grw

"::" is a default Frontpage DRW syntax, not valid in normal script
Use

strSql = "SELECT WavName FROM WavTable WHERE ID =" & intRanInt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top