|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL DROP Syntax
Ok, now I have an ASP file that is part of a management script I've been working on. I'm using (or at least trying to use) the SQL DROP command, but no matter what I do, I can't make it work. Can someone take a look at it and tell me where I've messed up? Thanks for your help.
<% Dim Mode,uid,uname Mode = Request.QueryString("mode") uid = Request.QueryString("uid") uname = Request.QueryString("uname") %> <% Dim cn,usr,SQL_usrtest Set cn = Server.CreateObject("ADODB.Connection") cn.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/userlist.mdb") Set usr = Server.CreateObject("ADODB.Recordset") SQL_usrtest = "SELECT * FROM users WHERE uid=" & uid usr.Open SQL_usrtest,cn,2,3 %> <% Dim cn1,ta,SQL_tatest Set cn1 = Server.CreateObject("ADODB.Connection") cn1.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/tasks.mdb") Set ta = Server.CreateObject("ADODB.Recordset") SQL_tatest = "SELECT * FROM " & uname ta.Open SQL_tatest,cn1,2,3 %> <% Dim SQL_ta Select Case Mode Case "edit" Response.Write("edit") usr("realname") = Request.Form("realname") usr("pass") = Request.Form("password") usr.Update Case "delete" Response.Write("del") usr.delete SQL_ta = "DROP TABLE " & uname ta.Open SQL_ta,cn1,2,3 End Select %> |
|
#2
|
||||
|
||||
|
First, you can't just say "It doesn't work". What are you trying to do, and what is actually happening? Are you getting an error? What error? Or just some unexpected result?
Until I know what you're trying to do, I'm not really going to get into the code, but it definitely looks unwieldy. Why are you making those 2 separate recordsets? Indent you case statements, it makes the code much easier to read.
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
|
#3
|
|||
|
|||
|
Hey karsh,
Thanks for the reply, sarcasm aside :-p. Usually I do indent my code, but when I pasted it in last night it didn't carry spacing with it, so that was lost, and it being somewhere in the neighborhood of 4:00 a.m., I was too tired to even realize that it would be a problem. The error I'm getting is an HTTP 500 error, nothing more, nothing less. I wouldn't have had to come here if it had given me a more specific error. I have two recordsets there because I'm manipulating data in two separate and, for security reasons, unlinked databases. What I really need help with is the syntax for the SQL DROP command. Everywhere I look I get one format, but for whatever reason it hasn't worked yet. Let's do this: forget my initial post and read this, then tell me what (if anything) is wrong with it. This is my understanding of the SQL DROP command. Step 1: Create a connection to the appropriate DB Step 2: Execute a command with the following wording: 'DROP TABLE Name'; Step 3: Close the connection Is there anything else? |
|
#4
|
|||
|
|||
|
If you are using Internet Explorer, open Tools - Internet Options - Advanced Options and uncheck the "show friendly http errors" setting. You should then get a more detailed explanation of the error you're getting when you run your code.
|
|
#5
|
|||
|
|||
|
Sweet :-) Good news, though. Thanks to karsh's criticism, I went through and cleaned the whole thing up and it now works flawlessly. Here's the code, as it works, for karsh to read so I can prove that sometimes I can come up with clean code lol. Btw, as I pasted it, it was spaced, so the spacing thing must not be on my end. Oh well, I suppose.
<% Dim Mode,uid,uname Mode = Request.QueryString("mode") uid = Request.QueryString("uid") uname = Request.QueryString("uname") %> <% Dim usr Set usr = Server.CreateObject("ADODB.Connection") usr.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/userlist.mdb") %> <% Dim ta Set ta = Server.CreateObject("ADODB.Connection") ta.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/tasks.mdb") %> <% Dim SQL_usrupd,SQL_usrdel,SQL_tadel Select Case Mode Case "edit" SQL_usrupd = "UPDATE users SET " SQL_usrupd = SQL_usrupd & "realname='" & Request.Form("realname") & "', pass='" & Request.Form("password") & "' " SQL_usrupd = SQL_usrupd & "WHERE uid=" & uid usr.Execute SQL_usrupd Case "delete" SQL_usrdel = "DELETE * FROM users WHERE uid=" & uid SQL_tadel = "DROP TABLE " & uname usr.Execute SQL_usrdel ta.Execute SQL_tadel End Select %> <html> <head> <title></title> <link rel="stylesheet" href="inc/stylesheet.css" class="text/css"> </head> <body> <font class="fontNormal"> Succesfully Updated Record<br> <a href="intrafront.asp?login=true" class="fontLinksDark">Back to Front Page</a> </font> </body> </html> <% usr.Close Set usr = Nothing ta.Close Set ta = Nothing %> |
|
#6
|
||||
|
||||
|
Glad it works, sometimes clean code helps for more than just looks
.For future reference, for posting code, put it in [code ] [/code ] (without the space) tags. This will preserve your spacing and tabs. Cheers |
|
#7
|
|||
|
|||
|
Thanks karsh :-).
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > SQL DROP Syntax |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|