continue execution after try/catch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • E. Kwong

    continue execution after try/catch

    I have a For loop to insert record to a SQL server database, like:


    For Each item As ListItem In cblxyz.Items
    If (item.Selected) Then
    .... do something
    Try
    srcxyz.Insert()
    Catch SQLExp As SqlException
    ....display error
    End Try
    End If
    Next



    Now when a duplicate record is encountered, it displays the error and then
    stops. I need the loop to go on after displaying the database error. Is
    there any way to do that? Or do I have to check whether the record is
    already existing in the database every single time before doing the Insert?



    Any insight appreciated.



    I'm using VS2005, SQL Server 2000, .Net 2.0





  • Jack Jackson

    #2
    Re: continue execution after try/catch

    What do you mean by "it stops".

    If the Catch doesn't do anything to cause execution to go anywhere
    else, execution should resume after the End Try.

    Set a breakpoint on the Catch and step it to see what happens.

    On Fri, 22 Aug 2008 17:45:58 -0700, "E. Kwong"
    <ekwong999AThot mail.comwrote:
    >I have a For loop to insert record to a SQL server database, like:
    >
    >
    >For Each item As ListItem In cblxyz.Items
    >If (item.Selected) Then
    >... do something
    >Try
    srcxyz.Insert()
    >Catch SQLExp As SqlException
    ....display error
    >End Try
    >End If
    >Next
    >
    >
    >
    >Now when a duplicate record is encountered, it displays the error and then
    >stops. I need the loop to go on after displaying the database error. Is
    >there any way to do that? Or do I have to check whether the record is
    >already existing in the database every single time before doing the Insert?
    >
    >
    >
    >Any insight appreciated.
    >
    >
    >
    >I'm using VS2005, SQL Server 2000, .Net 2.0
    >
    >
    >
    >

    Comment

    • PvdG42

      #3
      Re: continue execution after try/catch

      "E. Kwong" <ekwong999AThot mail.comwrote in message
      news:%23BE6cmLB JHA.5964@TK2MSF TNGP04.phx.gbl. ..
      >I have a For loop to insert record to a SQL server database, like:
      >
      >
      For Each item As ListItem In cblxyz.Items
      If (item.Selected) Then
      ... do something
      Try
      srcxyz.Insert()
      Catch SQLExp As SqlException
      ....display error
      End Try
      End If
      Next
      >
      >
      >
      Now when a duplicate record is encountered, it displays the error and then
      stops. I need the loop to go on after displaying the database error.
      Is there any way to do that? Or do I have to check whether the record is
      already existing in the database every single time before doing the
      Insert?
      >
      >
      >
      Any insight appreciated.
      >
      >
      >
      I'm using VS2005, SQL Server 2000, .Net 2.0
      >
      How do you "display error"? In a message box, by any chance?

      Comment

      • E. Kwong

        #4
        Re: continue execution after try/catch

        Thanks Jack Jackson and PvdG42.

        It turns out that I did not get the correct checkboxlist value to create the
        record.


        "PvdG42" <pvdg@toadstool .eduwrote in message
        news:uB6gcATBJH A.3888@TK2MSFTN GP05.phx.gbl...
        "E. Kwong" <ekwong999AThot mail.comwrote in message
        news:%23BE6cmLB JHA.5964@TK2MSF TNGP04.phx.gbl. ..
        >>I have a For loop to insert record to a SQL server database, like:
        >>
        >>
        >For Each item As ListItem In cblxyz.Items
        >If (item.Selected) Then
        >... do something
        >Try
        > srcxyz.Insert()
        >Catch SQLExp As SqlException
        > ....display error
        >End Try
        >End If
        >Next
        >>
        >>
        >>
        >Now when a duplicate record is encountered, it displays the error and
        >then stops. I need the loop to go on after displaying the database
        >error. Is there any way to do that? Or do I have to check whether the
        >record is already existing in the database every single time before doing
        >the Insert?
        >>
        >>
        >>
        >Any insight appreciated.
        >>
        >>
        >>
        >I'm using VS2005, SQL Server 2000, .Net 2.0
        >>
        How do you "display error"? In a message box, by any chance?
        >

        Comment

        Working...