Results 1 to 4 of 4

Thread: Help with Simple Error Handler

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    INDIA
    Posts
    169

    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 strSQLadoCon

    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"
    %> 

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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 
    rsdel
    .Open strSQLadoCon 

    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" 
    %> 

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    INDIA
    Posts
    169

    Re: Help with Simple Error Handler

    Hey,

    Thanx so much, will try it and let you know....

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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
  •  



Click Here to Expand Forum to Full Width