Print Page | Close Window

Record deletion

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3926
Printed Date: 30 March 2026 at 3:20am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Record deletion
Posted By: Ariod
Subject: Record deletion
Date Posted: 29 June 2003 at 7:21am
Can anyone suggest an easy way of deleting recordsets in a database via checkbox selection? (On the first page you select a set of records that you want to delete, and on the second page it removes them from the database)

I don't need the code, just a general idea.



Replies:
Posted By: Ariod
Date Posted: 29 June 2003 at 7:34am

Nevermind, I managed to do it:

 

Dim objRSPosudbe, niz, i

niz = Split(Request.Form("Vrati"), ",")

Set objRSPosudbe = Server.CreateObject("ADODB.Recordset")
objRSPosudbe.Open "Posudbe", objConn, , adLockOptimistic, adCmdTable

For i = LBound(niz) to UBound(niz)

  Do While Not objRSPosudbe.EOF
    If Trim(niz(i)) = Cstr(objRSPosudbe.Fields("ID").Value) Then
      objRSPosudbe.Delete     
      objRSPosudbe.MoveFirst
      Exit Do
    Else
      objRSPosudbe.MoveNext
    End If
  Loop
 
Next

objRSPosudbe.Close
Set objRSPosudbe = Nothing

objConn.Close
Set objConn = Nothing



Posted By: ljamal
Date Posted: 29 June 2003 at 10:48am
Why open up a recordset and loop when you can just execute a single SQL statement without the need of loops? SQL has a delete statement which allows you to delete all the records that matches your criteria.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Ariod
Date Posted: 29 June 2003 at 12:52pm

Dunno, that's my first script

Can you write that SQL statement?



Posted By: ljamal
Date Posted: 29 June 2003 at 12:59pm
assuming Request.Form("Vrati") contains numeric values

strSQL = "delete from [tablename] where ID in ("&Request.Form("Vrati" &")"
objConn.Open
objConn.Execute (strSQL)
objConn.Close

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Ariod
Date Posted: 29 June 2003 at 1:28pm

Hey, thanks, it works.

So, I'm allowed to use arrays SQL statements?

I mean, Request.Form("Vrati") behaves like an array, right?

And the statement would be:

...WHERE [VARIABLE] IN ([ARRAY])

?



Posted By: ljamal
Date Posted: 29 June 2003 at 2:18pm
Not arrays but comma delineated values with the IN keyword. YOu can also use a SQL statement such as
select ID from table

EXAMPLE
select * from table1 where ID in (select ID from table)

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Ariod
Date Posted: 29 June 2003 at 3:22pm

Thanks!

Can you suggest a good site that offers a good reference of the SQL statements?



Posted By: ljamal
Date Posted: 29 June 2003 at 3:31pm
http://www.sqlteam.com/ - http://www.sqlteam.com/

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



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