programming-examples/asp/Sessions_SQL/Delete Record with SQL statement.asp
2019-11-18 14:25:58 +01:00

58 lines
1.6 KiB
Plaintext

<TITLE>dbdeletemany.asp</TITLE>
<body bgcolor="#FFFFFF">
<HTML>
<!--#include file="lib_errors.asp"-->
<%
On Error Resume Next
myDSN = "DSN=Student;uid=student;pwd=magic"
mySQL = "DELETE FROM authors WHERE au_id=200"
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open myDSN
Conn.Execute mySQL,howmany
Response.Write "The statement " & mySQL & "<b> deleted " & howmany & " records</b><br>"
Call ErrorVBScriptReport("Deleting...")
Call ErrorADOReport(mySQL,conn)
Conn.Close
Set conn=Nothing
%>
</BODY>
</HTML>
The Error trapping library looks like this:
<%
Sub ErrorVBScriptReport(parm_msg)
If Err.number=0 Then
Exit Sub
End If
pad=" "
Response.Write "<b>VBScript Errors Occured!<br>"
Response.Write parm_msg & "</b><br>"
Response.Write pad & "Error Number= #<b>" & Err.number & "</b><br>"
Response.Write pad & "Error Desc.= <b>" & Err.description & "</b><br>"
Response.Write pad & "Help Context= <b>" & Err.helpcontext & "</b><br>"
Response.Write pad & "Help File Path=<b>" & Err.helpfile & "</b><br>"
Response.Write pad & "Error Source= <b>" & Err.source & "</b><br><hr>"
End Sub
Sub ErrorADOReport(parm_msg,parm_conn)
HowManyErrs=parm_conn.errors.count
If HowManyErrs=0 Then
Exit Sub
End If
pad=" "
Response.Write "<b>ADO Reports these Database Error(s) executing:<br>"
Response.Write SQLstmt & "</b><br>"
For counter= 0 To HowManyErrs-1
errornum=parm_conn.errors(counter).number
errordesc=parm_conn.errors(counter).description
Response.Write pad & "Error#=<b>" & errornum & "</b><br>"
Response.Write pad & "Error description=<b>"
Response.Write errordesc & "</b><p>"
Next
End Sub
%>