PDA

View Full Version : What 's Wrong with this Code


yoyali
07-10-2006, 09:44 AM
I'm Trying this code to switch the user group , so this code select users with groups only if the user doesn't have a group or does'nt exist redirect it to another page
Her is my code please check it

sql="select * from users,groups where users.user_id='"&id2&"' and users.group_id=groups.g_group_id"
set rs=conn.Execute(sql)
if rs.eof or rs("group_id")=null then
Response.Redirect("switch.asp?id="&session("session_id")&"&page=management")
else
dim group
group=rs("group_id")

end ifand It gives me this error message
Error Type:
(0x80020009)
Exception occurred.
Many Thax:)

Brandoe85
07-10-2006, 02:39 PM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)

As for the error, I can't see anything at first glance, try out these suggestions:
http://www.google.com/search?hl=en&q=asp+Exception+occurred&btnG=Google+Search

miranda
07-10-2006, 02:47 PM
First off that is not how to join 2 tables. Also if the user_id is an integer (number) datatype then you do not use the apostrophes around the variable


SELECT * FROM users u JOIN groups g ON u.group_id = g.g_group_id WHERE u.user_id = '" & id2 & "'"

degsy
07-12-2006, 03:09 PM
That method is fine to do an inner join on two table. It is just the shorthand way to do it.


SELECT user.userName, group.groupName
FROM group INNER JOIN user ON group.groupID = user.userGroup;


Is the same as

SELECT user.userName, group.groupName
FROM group, user
WHERE group.groupID = user.userGroup;

Spudhead
07-17-2006, 03:13 PM
It's probably not the cause of your error but I'd think carefully about doing a redirect while you've still got a recordset and a database connection open. Apart from that, error messages usually give line numbers. Did yours? Post it up if so.