0

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

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open"C:\Inetpub\wwwroot\template\database\database1.mdb"
pid=Request.Form("PatientId")

if Request.form("Patientname")="" then
  Set rs = Server.CreateObject("ADODB.Recordset")	
  rs.open "SELECT * FROM Patient WHERE PatientId=" & pid,conn
  %>
  <form method="post" action="demo_delete.asp">
  <table>
  <%for each x in rs.Fields%>
  <tr>
  <td><%=x.name%></td>
  <td><input name="<%=x.name%>" value="<%=x.value%>"></td>
  <%next%>
  </tr>
  </table>
  <br /><br />
  <input type="submit" value="Delete record">
  </form>
  
<%
else
  sql="DELETE FROM Patient"
  sql=sql & " WHERE PatientId=" & pid
  on error resume next
  conn.Execute sql
  if err<>0 then
    response.write("No update permissions!")
  else
    response.write("Record " & pid & " was deleted!")
  end if
end if
conn.close
%>

anyone have idea ,can help me

best Regards

Edited by aalqa: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by aalqa
0
strConnection = SOME DATABASE CONNECTION

set dbConnection = server.CreateObject ("ADODB.Connection")
dbConnection.ConnectionString = strConnection
dbConnection.Open

commDeleteI__intRecordsIDs = Request("del")
set commDeleteI = Server.CreateObject("ADODB.Command")
commDeleteI.ActiveConnection = dbConnection
commDeleteI.CommandText = "DELETE FROM Records WHERE ID IN (" + Replace(commDeleteI__intRecordsIDs, "'", "''") + ")"
commDeleteI.CommandType = 1
commDeleteI.CommandTimeout = 0
commDeleteI.Prepared = true
commDeleteI.Execute()
set commDeleteI = Nothing
0

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"

0

thank you I solve my problem and the solution is

<%
Dim adoCon            
Dim rs    
Dim strSQL            
Dim lngRecordNo     
'Read in the record number to be deleted
lngRecordNo = CLng(Request.QueryString("id"))
 
Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("C:\Inetpub\wwwroot\template\database\database1.mdb") 



Set rs = Server.CreateObject("ADODB.Recordset")  
  
strSQL = "SELECT Patient.* FROM Patient WHERE Patient.PatientId=" & lngRecordNo 
Response.write strSQL
rs.LockType = 3  
rs.Open strSQL, adoCon 
if	rs.EOF then 

	Response.Write("<h3>&nbsp;&nbsp;please Enter a Vaild  Number</h3><br><br>")
		Else 
%>


<html>
<title><h2>Delete Form </h2></title>
  
 
<body bgcolor="white" text="black">
 
<form name="form" method="post" action="demo_delete.asp">
 <table>
 <td>Patient Name:</td>
<td><input name="name" value="<% =rs("Patientname") %>"></td>
</tr><tr>
<td>Sex :</td>
<td><input name="sex" value="<% =rs("Sex") %>"></td>
</tr><tr>
<td>phone :</td>
<td><input name="phone" value="<% =rs("phone") %>"></td>
</tr><tr>
<td>Date:</td>
<td><input name="Date" value="<% =rs("Datee") %>"></td>
</tr>
</table>
   
   <input type="hidden" name="ID_no" value="<% = lngRecordNo%>">
   <input type="submit" name="Submit" value="Delete">
</form>
 
 
 <p>
 <p>
<a href="delete_select.asp" title="Back To Delete Page">Back To Delete Page</a>

</body>
</html>



<%
End IF
rs.Close
adoCon.Close
Set rs = Nothing
Set adoCon = Nothing

%>
<html>
<body>

<h2>Delete Record</h2>
 
<% 'Dimension variables
Dim adoCon          'Holds the Database Connection Object 
Dim rs   'Holds the recordset for the record to be deleted 
Dim strSQL          'Holds the SQL query to query the database 
Dim lngRecordNo     'Holds the record number to be deleted

'Read in the record number to be deleted
lngRecordNo = Request.form ("ID_no")
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("C:\Inetpub\wwwroot\template\database\database1.mdb")

Set rs = Server.CreateObject("ADODB.Recordset")  
  
strSQL = "Delete * FROM Patient WHERE PatientId="&lngRecordNo  
 rs.Open strSQL, adoCon  
 
Response.Write"<center><h2>patient was delete/<h2></center>"

 
adoCon.Close
Set rs = Nothing
Set adoCon = Nothing
Response.Redirect "delete_select.asp"
%>   
   


  
 
  
</body>
</html>

Edited by aalqa: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.