Print Page | Close Window

deleting from a specific table

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=8863
Printed Date: 30 March 2026 at 12:17pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: deleting from a specific table
Posted By: mossmannen
Subject: deleting from a specific table
Date Posted: 13 January 2004 at 4:11pm

Hi!

In my access db i have a couple of different tables.
I want to delete a specifc record from a specific table.
What I've done so far is:
A dropdown menu where I can choose the table and then click submit
Now, the records within that table is shown. So far so good.
What I want to do now is to be able to click on a record and it will be deleted. The problem is the script to delete the specific record from that table.
The code for the problem-script is:

<% 
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"


Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM What goes here? WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 

I think the problem is in the Select * from ????
What goes after "from"?

What could I do?

 




Replies:
Posted By: Mart
Date Posted: 13 January 2004 at 4:15pm
You put the name of the table there...


Posted By: mossmannen
Date Posted: 13 January 2004 at 5:05pm

Yeah...I know that....

But i selected the table from the dropdownmenu clicked submit, then all the records from the table selected is shown...but i don't know what to write after THIS "FROM". I have 6 different tables to choose from...

I post the whole code below:

The dropdown that let me select the table: (delete_link_form.asp)


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../style/style.css" rel="stylesheet" type="text/css">
</head>

<body>
 <form name="form" method="post" action="delete_link_select.asp">
   <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Category:</td>
      <td><select name="catgy">
          <option>MAin</option>
          <option>Music</option>
          <option>Pics</option>
          <option>Movie</option>
          <option>Otrher</option>
          <option>Admin</option>
        </select></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
     </table>
 </form>
</body>
</html>

The page listing the records from the table selected in the previous dropdown (delete_select.asp)

<% 
Dim adoCon     
Dim rsDeleteLink
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"
Set rsDeleteLink = Server.CreateObject("ADODB.Recordset")

     category = Request("catgy")
     select case category
      case "Main"
       strSQL="select * from Main"
      case "Music"
       strSQL="select * from Music"
      case "Pics"
       strSQL="select * from Pics"
      case "Movie"
       strSQL="select * from Movie"
      case "Other"
       strSQL="select * from Other"
      case "Admin"
       strSQL="select * from Admin"
     end select
     
rsDeleteLink.Open strSQL, adoCon

Do While not rsDeleteLink.EOF

     Response.Write ("<br>")
     Response.Write ("<a href=""delete_link.asp?ID=" & rsDeleteLink("ID") & """>")
     Response.Write (rsDeleteLink("Link_Text"))
     Response.Write ("</a>")
     Response.Write ("<br>")
     Response.Write (rsDeleteLink("Link"))
     Response.Write ("<br>")
  rsDeleteLink.MoveNext

Loop


rsDeleteLink.Close
Set rsDeleteLink = Nothing
Set adoCon = Nothing
%>

The code that should be executed when clicking on one of the listed records (delete_link.asp)


<%
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"


Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM ????? WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 


So...what goes instead of the question marks? Or could this be solved easier?



Posted By: michael
Date Posted: 13 January 2004 at 5:35pm
Originally posted by mossmannen mossmannen wrote:

<% 
Dim adoCon     
Dim rsDeleteLink
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"
Set rsDeleteLink = Server.CreateObject("ADODB.Recordset")

     category = Request("catgy")
     select case category
      case "Main"
       strSQL="select * from Main"
      case "Music"
       strSQL="select * from Music"
      case "Pics"
       strSQL="select * from Pics"
      case "Movie"
       strSQL="select * from Movie"
      case "Other"
       strSQL="select * from Other"
      case "Admin"
       strSQL="select * from Admin"
     end select
     
rsDeleteLink.Open strSQL, adoCon

Do While not rsDeleteLink.EOF

     Response.Write ("<br>")
     Response.Write ("<a href=""delete_link.asp?ID=" & rsDeleteLink("ID") & "&cat=" & category & ">")
     Response.Write (rsDeleteLink("Link_Text"))
     Response.Write ("</a>")
     Response.Write ("<br>")
     Response.Write (rsDeleteLink("Link"))
     Response.Write ("<br>")
  rsDeleteLink.MoveNext

Loop


rsDeleteLink.Close
Set rsDeleteLink = Nothing
Set adoCon = Nothing
%>

The code that should be executed when clicking on one of the listed records (delete_link.asp)


<%
Dim adoCon     
Dim rsDeleteEntry 
Dim strSQL      
Dim lngRecordNo   

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DBQ=" & Server.MapPath("../../db/db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=12345;"

category = Request.QueryString("cat")
Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

       strSQL="SELECT * FROM " & category & " WHERE ID=" & lngRecordNo
  
rsDeleteEntry.LockType = 3

rsDeleteEntry.Open strSQL, adoCon

rsDeleteEntry.Delete


rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing


Response.Redirect "../../index.asp"
%> 


Be aware though that this is very unsecure, you should definately secure the script as otherwise everyone can put in a querystring and delete your records....



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: mossmannen
Date Posted: 13 January 2004 at 6:35pm

Thanks alot.

I don't know how to secure the script. So this is good enough for me.



Posted By: mossmannen
Date Posted: 14 January 2004 at 2:47pm

Tried it.

doesn't work. Error in FROM clause



Posted By: Mart
Date Posted: 14 January 2004 at 3:01pm
Change
category = Request.QueryString("cat")
To
category = Request.Form("cat")
Because you are using the post verb not get...


Posted By: mossmannen
Date Posted: 14 January 2004 at 3:08pm

sorry... that did not help

still the same problem



Posted By: michael
Date Posted: 15 January 2004 at 6:31pm
Actually it is querystring and it does work, do a response.write strSQL to see what the sql query looks like...

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net