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

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

Thank you Mr.ArtistScope

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"

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.