Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Capturing the UN-UPDATED records

Capturing the UN-UPDATED records

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Sundar
    wrote on last edited by
    #1

    for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....

    A P 2 Replies Last reply
    0
    • J John Sundar

      for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....

      A Offline
      A Offline
      Ariel Kazeed
      wrote on last edited by
      #2

      Since this is not VB6 and you cannot Resume Next On Error, I guess you better validate what you're updating before trying to update it, and if it doesn't validate, not try to update. Simply. Thus, you get no exceptions and the for loops for as long as you want it to loop :)

      Kazz


      "Users are there to click on things, not think. Let the archs do the damn thinking."

      1 Reply Last reply
      0
      • J John Sundar

        for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....

        P Offline
        P Offline
        pmarfleet
        wrote on last edited by
        #3

        John Sundar wrote:

        once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop????

        The try/catch block is within the body of the loop. If an error occurs during one iteration of the loop, it will be caught and the code will proceed to subsequent iterations.

        John Sundar wrote:

        i tried.. but getting error...

        You need to post details of the error if you want help. We're not mindreaders.

        John Sundar wrote:

        how to achieve it?

        Post details of your error, and maybe you'll get some help.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups