473,804 Members | 3,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem deleting multiple rows - Nearly there, PLEASE HELP

66 New Member
Hi all,

im nearly there with this one and im sure it shouldnt be hard to solve, i just cant seem to find the solution.

ive got records being displayed, the user can then tick what records to delete... click delete.. it shows deleted records then you can go back to the screen, It works if one record is selected but any more it doesnt delete any so im sure there is a problem with my SQL statement.

the code for the 2 pages have been shown below:

The code for the selection page
=============== ========
Expand|Select|Wrap|Line Numbers
  1.       <div align="center">
  2.         <%
  3. If rssearchcnx.BOF and rssearchcnx.EOF Then%> 
  4.     We appolagise, but no flights were found matching your search
  5.       </div>
  6.       <p align="center"><a href="search.asp" target="mainFrame">please try again</a></p>
  7. <%Else%>
  8.  
  9. <%If Not rssearchcnx.BOF Then%>
  10. <%
  11.     Do While Not rssearchcnx.EOF
  12.     %>
  13. <tr>
  14.         <td ><%=rssearchcnx("flight_id")%></td>
  15.         <td></td>
  16.         <td>
  17.         <form name="form" method="post" action="delete.asp">
  18.         <input type="checkbox" name="flight_id" value="<%=(rssearchcnx.Fields.Item("flight_id").Value)%>"></td>
  19.  
  20.       </tr>
  21.     <% rssearchcnx.MoveNext
  22.     Loop
  23.     %>
  24.  
  25. </table>
  26.  
  27. <%End If%>
  28. <%End If%>
  29.     <input type="submit" value="Delete Selected Records">
  30. </form>
  31. <%
  32. rssearchcnx.Close
  33. searchcnx.Close
  34. %>
  35.  
code for the delete action page
=============== =======
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim flight_id
  4.  
  5. flight_id = Request.Form("flight_id")
  6.  
  7.  
  8. SQL="DELETE * FROM tbl_flight_details WHERE flight_id ='"+Request.Form("flight_id")+"'"
  9.  
  10.  Set MyConn=Server.CreateObject("ADODB.Connection")
  11. MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ddwassignment3\airlines.mdb"
  12.  
  13. Set MyRS=Server.CreateObject("ADODB.RecordSet")
  14. MyRS.Open SQL,MyConn
  15.  
  16. %>
  17.  
  18. </p>
  19.       <table width="37%" border="0" align="center">
  20.         <tr>
  21. <td align="center"><% Response.Write("<font face=Calibri>You have deleted flight number <B><font face=Calibri color=Red>" & flight_id)%>
  22.  
any help will be MUCH appreciated

kind regards

jason
Mar 10 '08 #1
5 1906
jeffstl
432 Recognized Expert Contributor
You have to execute the DELETE SQL in a loop (more then once) to delete multiple records.

You will need a check that gathers all the id's checked by the user into an array.

The you will need to loop through that array and run the SQL delete statement for EACH id in the array.

With this current set up I am not sure which direction to tell you. I would probably instead of letting them do check boxes and submitting a whole bunch to process, you could set it up where they can delete one at a time quicker by redirecting them to the page displaying the records.

Print this link out next to each record:
Expand|Select|Wrap|Line Numbers
  1. 'FORM PAGE
  2. response.write <a href=delete.asp?id=" & rssearchcnx.Fields.Item("flight_id").Value & ">Delete</a>"
  3.  
  4. 'THEN ON YOUR DELETE.ASP
  5. 'take the id from the querystring instead
  6. <%
  7.  
  8. Dim flight_id
  9.  
  10. flight_id = Request.Querystring("id")
  11.  
  12.  
  13. SQL="DELETE * FROM tbl_flight_details WHERE flight_id ='"+Request.Form("flight_id")+"'"
  14.  
  15.  Set MyConn=Server.CreateObject("ADODB.Connection")
  16. MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ddwassignment3\airlines.  mdb"
  17.  
  18. 'execute sql string!!
  19. MyConn.execute SQL
  20.  
  21. 'then just redirect back to your page listing all the records and delete links!
  22. response.redirect("formpage.asp")
  23.  
  24. 'dont really need to create a record set to execute a DELETE, only when ur 'SELECTING records I think
  25. 'Set MyRS=Server.CreateObject("ADODB.RecordSet")
  26. 'MyRS.Open SQL,MyConn
  27.  
  28. %>
  29.  
  30.  
Mar 10 '08 #2
jasone
66 New Member
Hi thanks for your response, a little unsure where to put this data, is it possible for you to insert the script into the script i have already posted, and then post it back on here?

many many thanks

jason
Mar 10 '08 #3
jasone
66 New Member
i forgot to say im using checkboxes.. so there is no need for the delete text next to each record
Mar 10 '08 #4
jeffstl
432 Recognized Expert Contributor
All I can say like stated before is that in order to use checkboxes and process many deletes at once, you will need to set up and pass an array of "id" numbers to loop through.

Im not sure how many records you are dealing with when you print out the area for them to select the checkboxes, so Im not sure what the best solution is, Its not simple to determine how many checkboxes are checked on a page when there could be 5 or there could be a 1000.

Just off hand on your delete.asp page you will need something like this where MyCheckBox is your array of checkboxes:

Again to avoid all this, you could use my example where there is a delete link next to each record and they click it and it goes right back to the page they were just viewing with the record deleted.

Expand|Select|Wrap|Line Numbers
  1.  
  2. for FlightID=0 to MyRS.RecordCount
  3.      if MyCheckBox(FlightID).Value = 1 then
  4.           'execute delete SQL here using FlightID
  5.      end if
  6.  
  7. Next
  8.  
  9.  
Mar 10 '08 #5
jhardman
3,406 Recognized Expert Specialist
Hey Jasone,

If Jeff's instructions were a jump for you, try a multi-step approach like this.

1- as it is you are opening up a new form for each row, only one form is going to be sent to the next page, so make sure the <form> tag is before the loop,

2- open up the data posted from your form to make sure it is in a good format:
Expand|Select|Wrap|Line Numbers
  1. for each x in request.form
  2.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  3. next
If all of the flight_id numbers had the same input name (name="flight_i d") then you should get a list in response like this:
Expand|Select|Wrap|Line Numbers
  1. flight_id: 23, 75, 63, 192
Make sure these are all the records you want to delete before you go on.

3- Open the db and SELECT these records. Make sure you are getting the right records. I actually recommend you put up a confirmation dialogue before you delete, but regardless, I would open with a SELECT statement first.
Expand|Select|Wrap|Line Numbers
  1. query = "SELECT * FROM tbl_flight_details WHERE flight_id IN " & Request.Form("flight_id")
Notice the "IN" keyword allows you to select values from a list, otherwise, you are saying you want the flight_id to equal 23,75,63,192 and there is no flight id that equals that. Look at the list this pulls up to make sure it is pullingup the right records (as I mentioned before, I usually leave this step in the final version as a confirmation "Are you sure you want to delete these recdords?")
Expand|Select|Wrap|Line Numbers
  1. response.write "<table><tr>"
  2. for each x in objRS.fields
  3.    response.write "<th>" & x.name & "</th>"
  4. next
  5. response.write "</tr>" & vbNewLine
  6.  
  7. do until objRS.eof
  8.    response.write "<tr>"
  9.  
  10.    for each x in objRS.fields
  11.       response.write "<td>" & x.value & "</td>"
  12.    next
  13.  
  14.    response.write "</tr>"
  15.    objRS.moveNext
  16. loop
  17.  
  18. Response.write "</table>"
  19.  
4- if this looks good, then to delete you just need to change the word "SELECT" to "DELETE" and it will go.

Let me know if this helps.

Jared
Mar 12 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
14744
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this: for (int i=0; i < dataView.Count; i++) if (dataGrid.IsSelected(i)) dataView.Delete(i);
7
9784
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround I've got stuck trying to write a DELETE statement. Here's the table I'm working on: CREATE TABLE `articles_categories` (
2
1670
by: Brad Pears | last post by:
I am working on a new vb.net 2005 project using SQL server 2000 as the backend db. I have a listview where control I want a user to be able to select either just one or multiple rows in the listview and perform an action on them. If the user chooses to delete these rows I wonder what the best way to handle the deletion of multiple rows is... Right now I have a stored procedure for deleteing jsut opne row. i.e delete from {tablename}...
3
3930
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is messing up. Problems:
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.