943,198 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 192
  • ASP RSS
Jul 12th, 2010
0

Deleting records by ConnectingString

Expand Post »
Good morning every one,
I want to delete records in my database by using connectingString e.g write id=6
to delete instead of this code
ASP Syntax (Toggle Plain Text)
  1. <%
  2. set conn=Server.CreateObject("ADODB.Connection")
  3. conn.Provider="Microsoft.Jet.OLEDB.4.0"
  4. conn.Open"C:\Inetpub\wwwroot\template\database\database1.mdb"
  5. pid=Request.Form("PatientId")
  6.  
  7. if Request.form("Patientname")="" then
  8. Set rs = Server.CreateObject("ADODB.Recordset")
  9. rs.open "SELECT * FROM Patient WHERE PatientId=" & pid,conn
  10. %>
  11. <form method="post" action="demo_delete.asp">
  12. <table>
  13. <%for each x in rs.Fields%>
  14. <tr>
  15. <td><%=x.name%></td>
  16. <td><input name="<%=x.name%>" value="<%=x.value%>"></td>
  17. <%next%>
  18. </tr>
  19. </table>
  20. <br /><br />
  21. <input type="submit" value="Delete record">
  22. </form>
  23.  
  24. <%
  25. else
  26. sql="DELETE FROM Patient"
  27. sql=sql & " WHERE PatientId=" & pid
  28. on error resume next
  29. conn.Execute sql
  30. if err<>0 then
  31. response.write("No update permissions!")
  32. else
  33. response.write("Record " & pid & " was deleted!")
  34. end if
  35. end if
  36. conn.close
  37. %>
anyone have idea ,can help me

best Regards
Last edited by aalqa; Jul 12th, 2010 at 4:47 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aalqa is offline Offline
9 posts
since Jul 2010
Jul 12th, 2010
0
Re: Deleting records by ConnectingString
ASP Syntax (Toggle Plain Text)
  1.  
  2. strConnection = SOME DATABASE CONNECTION
  3.  
  4. set dbConnection = server.CreateObject ("ADODB.Connection")
  5. dbConnection.ConnectionString = strConnection
  6. dbConnection.Open
  7.  
  8. commDeleteI__intRecordsIDs = Request("del")
  9. set commDeleteI = Server.CreateObject("ADODB.Command")
  10. commDeleteI.ActiveConnection = dbConnection
  11. commDeleteI.CommandText = "DELETE FROM Records WHERE ID IN (" + Replace(commDeleteI__intRecordsIDs, "'", "''") + ")"
  12. commDeleteI.CommandType = 1
  13. commDeleteI.CommandTimeout = 0
  14. commDeleteI.Prepared = true
  15. commDeleteI.Execute()
  16. set commDeleteI = Nothing
Reputation Points: 5
Solved Threads: 14
Junior Poster
ArtistScope is offline Offline
146 posts
since Jun 2010
Jul 13th, 2010
0
Re: Deleting records by ConnectingString
Thank you Mr.ArtistScope
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aalqa is offline Offline
9 posts
since Jul 2010
Jul 13th, 2010
0
Re: Deleting records by ConnectingString
You can delete one or many.

If you have a page of rows, each with a checkbox and ID as identifier, sending to a form with this code will delete all the IDs submitted.

For example, from a string like "23,35,36,47,51"
Reputation Points: 5
Solved Threads: 14
Junior Poster
ArtistScope is offline Offline
146 posts
since Jun 2010
Jul 14th, 2010
0
Re: Deleting records by ConnectingString
thank you I solve my problem and the solution is
ASP Syntax (Toggle Plain Text)
  1. <%
  2. Dim adoCon
  3. Dim rs
  4. Dim strSQL
  5. Dim lngRecordNo
  6. 'Read in the record number to be deleted
  7. lngRecordNo = CLng(Request.QueryString("id"))
  8.  
  9. Set adoCon = Server.CreateObject("ADODB.Connection")
  10.  
  11. adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("C:\Inetpub\wwwroot\template\database\database1.mdb")
  12.  
  13.  
  14.  
  15. Set rs = Server.CreateObject("ADODB.Recordset")
  16.  
  17. strSQL = "SELECT Patient.* FROM Patient WHERE Patient.PatientId=" & lngRecordNo
  18. Response.write strSQL
  19. rs.LockType = 3
  20. rs.Open strSQL, adoCon
  21. if rs.EOF then
  22.  
  23. Response.Write("<h3>&nbsp;&nbsp;please Enter a Vaild Number</h3><br><br>")
  24. Else
  25. %>
  26.  
  27.  
  28. <html>
  29. <title><h2>Delete Form </h2></title>
  30.  
  31.  
  32. <body bgcolor="white" text="black">
  33.  
  34. <form name="form" method="post" action="demo_delete.asp">
  35. <table>
  36. <td>Patient Name:</td>
  37. <td><input name="name" value="<% =rs("Patientname") %>"></td>
  38. </tr><tr>
  39. <td>Sex :</td>
  40. <td><input name="sex" value="<% =rs("Sex") %>"></td>
  41. </tr><tr>
  42. <td>phone :</td>
  43. <td><input name="phone" value="<% =rs("phone") %>"></td>
  44. </tr><tr>
  45. <td>Date:</td>
  46. <td><input name="Date" value="<% =rs("Datee") %>"></td>
  47. </tr>
  48. </table>
  49.  
  50. <input type="hidden" name="ID_no" value="<% = lngRecordNo%>">
  51. <input type="submit" name="Submit" value="Delete">
  52. </form>
  53.  
  54.  
  55. <p>
  56. <p>
  57. <a href="delete_select.asp" title="Back To Delete Page">Back To Delete Page</a>
  58.  
  59. </body>
  60. </html>
  61.  
  62.  
  63.  
  64. <%
  65. End IF
  66. rs.Close
  67. adoCon.Close
  68. Set rs = Nothing
  69. Set adoCon = Nothing
  70.  
  71. %>
ASP Syntax (Toggle Plain Text)
  1. <html>
  2. <body>
  3.  
  4. <h2>Delete Record</h2>
  5.  
  6. <% 'Dimension variables
  7. Dim adoCon 'Holds the Database Connection Object
  8. Dim rs 'Holds the recordset for the record to be deleted
  9. Dim strSQL 'Holds the SQL query to query the database
  10. Dim lngRecordNo 'Holds the record number to be deleted
  11.  
  12. 'Read in the record number to be deleted
  13. lngRecordNo = Request.form ("ID_no")
  14. 'Create an ADO connection object
  15. Set adoCon = Server.CreateObject("ADODB.Connection")
  16. 'Set an active connection to the Connection object using a DSN-less connection
  17. adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("C:\Inetpub\wwwroot\template\database\database1.mdb")
  18.  
  19. Set rs = Server.CreateObject("ADODB.Recordset")
  20.  
  21. strSQL = "Delete * FROM Patient WHERE PatientId="&lngRecordNo
  22. rs.Open strSQL, adoCon
  23.  
  24. Response.Write"<center><h2>patient was delete/<h2></center>"
  25.  
  26.  
  27. adoCon.Close
  28. Set rs = Nothing
  29. Set adoCon = Nothing
  30. Response.Redirect "delete_select.asp"
  31. %>
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. </body>
  39. </html>
Last edited by aalqa; Jul 14th, 2010 at 7:29 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aalqa is offline Offline
9 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: uploading in asp
Next Thread in ASP Forum Timeline: ASP Join Problem?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC