|
-
Sep 20th, 2007, 12:07 PM
#1
Thread Starter
Addicted Member
Help with Simple Error Handler
Hi,
This error handler is not working...can anybody help please....
PHP Code:
<%
Dim adoCon
Dim rsAddComments
Dim strSQL
intID = Cint(Request.Form("id"))
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/dritest/db/DRI.mdb") & ";Jet OLEDB:Database Password=admin"
Set rsdel = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM dritbl where ID=" & intID
rsdel.LockType = 3
rsdel.Open strSQL, adoCon
If Not rsdel.EOF And Err = 0 Then
rsdel.delete
On Error Goto 0
On Error Resume Next
If Err = 0 Then
Response.write "Record has been Deleted"
Else
Response.Write "Update Error #" & Err.Number
End If
Else
If Err = 0 Then
Response.Write "Record Does Not Exist"
Else
Response.Write "Database Error #" & Err.Number
End If
End If
rsdel.Close
Set rsdel = Nothing
Set adoCon = Nothing
Response.Redirect "control.asp"
%>
-
Sep 20th, 2007, 03:08 PM
#2
Re: Help with Simple Error Handler
I would try it more like this. I'm just air coding here so there may be a few syntax errors.
PHP Code:
<%
Dim adoCon
Dim rsAddComments
Dim strSQL
On Error Resume Next
intID = Cint(Request.Form("id"))
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/dritest/db/DRI.mdb") & ";Jet OLEDB:Database Password=admin"
Set rsdel = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM dritbl where ID=" & intID
rsdel.LockType = 3
rsdel.Open strSQL, adoCon
If Err.Number = 0 Then
If Not rsdel.EOF Then
rsdel.delete
If Err = 0 Then
Response.write "Record has been Deleted"
Else
Response.Write "Update Error #" & Err.Number
End If
Else
Response.Write "Record Does Not Exist"
End if
Else
Response.Write "Database Error #" & Err.Number
End If
If Not rsdel is Nothing Then
If rsdel.State <> 0 Then
rsdel.Close
End If
Set rsdel = Nothing
End If
If Not adoCon Is Nothing Then
If adoCon.State <> 0 Then
adoCon.Close
End if
Set adoCon = Nothing
End If
Response.Redirect "control.asp"
%>
-
Sep 24th, 2007, 02:05 AM
#3
Thread Starter
Addicted Member
Re: Help with Simple Error Handler
Hey,
Thanx so much, will try it and let you know....
-
Sep 25th, 2007, 12:54 PM
#4
PowerPoster
Re: Help with Simple Error Handler
try this, not tested but based on the other user's contribution also, however please see the bottom line of the code as that is the main reason your error handling is not working! 
Code:
<%
Option Explicit
Dim adoCon, rsdel
On Error Resume Next
intID = Cint(Request.Form("id"))
'// Create DB Objects
Set adoCon = CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/dritest/db/DRI.mdb") & ";Jet OLEDB:Database Password=admin"
Set rsdel = adoCon.Execute("SELECT ID FROM dritbl where ID=" & intID)
'// Error Handling
If Err = 0 Then
If Not rsdel.EOF Then
adoCon.Execute("Delete * FROM dritbl where ID=" & intID)
If Err = 0 Then
Response.write "Record has been Deleted"
Else
Response.Write "Update Error #" & Err.Number
End If
Else
Response.Write "Record Does Not Exist"
End if
Else
Response.Write "Database Error #" & Err.Number
End If
'// Close DB Objects ' Using on error resume next above will just bypass
Set rsdel = Nothing ' these if it errors. To check the open state use
adoCon.Close ' "Const adStateOpen = &H00000001" at top and
Set adoCon = Nothing ' then use "If adoCon.State = adStateOpen Then"
'// If this is left in it you will not see the messages above
'// Response.Redirect "control.asp"
%>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|