Hi,
I have my query like this
Code:
Set rs = Server.CreateObject("adodb.RecordSet")
str = "SELECT Max(NId) as maximus from subject_students where User_Id='" & getuserid & "'"
Response.write str
rs.Open str,Conn, 2, 2
If not rs.eof then
Response.write "here"
else
Response.write "there"
End if
i have a student whose user_Id is not in the subject_students table but when i fire the query the output for response.write is "here" when it should be "there"
Can someone tell me whats wrong
todd
Obviously it's not EOF so, I would try running this in query analyzer with the user ID set as you want. Then see what you get.
Also - check the SQL string in debug and make sure it's as you want it to be.
Was this answer helpful ?
Yes No
laura,
i tried the code in query analyzer it came as blank as the user's id is not in the table but when i try the code in the asp page its not working
can you tell me what might be wrong
Was this answer helpful ?
Yes No
I might be totally and stupidingly wrong, but does the cursor types here wud change something.
I mean what if u change it to??
Code:
rs.Open str,Conn, 3, 3
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by todd2006 laura,
i tried the code in query analyzer it came as blank as the user's id is not in the table but when i try the code in the asp page its not working
can you tell me what might be wrong |
That's your answer. When the user id is not in the table, the query is returning NULL rather than not returning anything at all. Change your if statement to check for DBNull rather than record count.
Was this answer helpful ?
Yes No
hi,
if i fire my query like this
str = "SELECT * from subject_students where User_Id='" & getuserid & "'"
it goes in the else condition
its just weird how come when i fire for max it doesnt work
any idea
todd
Was this answer helpful ?
Yes No
Ok i do it like this
Code:
Set rs = Server.CreateObject("adodb.RecordSet")
str = "SELECT * from subject_students where User_Id='" & getuserid & "'"
Response.write str
rs.Open str,Conn, 2, 2
If not rs.eof then
Response.write "here"
else
Response.write "there"
End if
ok now it works but if the user is in the table how do i get the Max(NId) in the if condition
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by todd2006 Ok i do it like this
Code:
Set rs = Server.CreateObject("adodb.RecordSet")
str = "SELECT * from subject_students where User_Id='" & getuserid & "'"
Response.write str
rs.Open str,Conn, 2, 2
If not rs.eof then
Response.write "here"
else
Response.write "there"
End if
ok now it works but if the user is in the table how do i get the Max(NId) in the if condition |
Did you read my post? Max() always returns something. Don't check for eof, check for NULL.
Was this answer helpful ?
Yes No
hi,
can you tell me how do u check for null in the if loop line
i have never done that
todd
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by todd2006 hi,
can you tell me how do u check for null in the if loop line
i have never done that
todd |
I'm not an ASP programmer, so I don't know in this case. Try asking over in the ASP forum, or maybe a lurker here can answer that one better than me.
FWIW, it's always a good programming practice to check for NULL values, unless the column is not nullable to begin with.
Was this answer helpful ?
Yes No