Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fun with sql and request.querystring ;o)

Status
Not open for further replies.

sezme

Programmer
Oct 31, 2003
26
0
0
GB

I am having trouble accessing data

Dim Ex = Request.Querystring("x")

sql = "Select * from Exp Where ExKey = '" & Ex & "'"

this works fine unless there is no 'x' querystring - then the sql statement will return data where ExKey = 0 - why should this do this ?

response.write sql produces

Select * from Exp Where ExKey = ''

any suggestions ?

s.


 
Should only return where x is an empty string. What data type is "ExKey"?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
If datatype is integer, then you should not have quotes on the original string....

if isNumeric(Ex) then
sql = "Select * from Exp Where ExKey = " & Ex
end if




Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 

thanks for your help

i am trying this

if isNumeric(request.querystring("x")) then
etc

but i dont understand why the statement expresses true when there is no id querystring ?

any ideas ?
 
you may need to do this...

if isNumeric(request.querystring(&quot;x&quot;)) AND trim(request.querystring(&quot;x&quot;)) <> &quot;&quot; then

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 


thanks a lot again

i'm going to chance my cheeky arm here

i'm new to asp / sql etc and i'm having trouble understanding insert.

if i insert a new record into a database, how do i get the value for the primary key ? do i have to search through the existing table to find the highest number ? is there some function that i need to know ? the way i have done it is by running an sql statement and getting the highest number, but this seems longwinded.

thanks in advance
 
The best way is to use a stored procedure and return the value of @@IDENTITY which is the primary key for the row that was inserted last.

I haven't tried it but, you might be able to get the value like this...

cn.execute(&quot;insert into myTable values('someVal')&quot;)
set rs = cn.execute (&quot;select @@identity&quot;)

Look here...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top