Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Record deletion
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Record deletion

 Post Reply Post Reply Page  12>
Author
Ariod View Drop Down
Newbie
Newbie


Joined: 27 June 2003
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ariod Quote  Post ReplyReply Direct Link To This Post Topic: Record deletion
    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.
Back to Top
Ariod View Drop Down
Newbie
Newbie


Joined: 27 June 2003
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ariod Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Ariod View Drop Down
Newbie
Newbie


Joined: 27 June 2003
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ariod Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2003 at 12:52pm

Dunno, that's my first script

Can you write that SQL statement?

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Ariod View Drop Down
Newbie
Newbie


Joined: 27 June 2003
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ariod Quote  Post ReplyReply Direct Link To This Post 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])

?

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
Ariod View Drop Down
Newbie
Newbie


Joined: 27 June 2003
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ariod Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2003 at 3:22pm

Thanks!

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

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.