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. try/catch

try/catch

Scheduled Pinned Locked Moved ASP.NET
helpquestiondatabase
2 Posts 2 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.
  • S Offline
    S Offline
    Satish_S
    wrote on last edited by
    #1

    ID col1 col2 col3 col4 rescol
    121 0 1 2 6 YES
    122 0 1 2 6 YES
    123 0 0 9 0 NULL

    Above are the Sql rows and if my function finds null for the ID=123 as 9 of col3 then i need to locate for before id's rescol and if that also find as null then i need to fetch for the above row of 121, like this till i am not getting res col as null i need to fix a loop how can i do this? In try catch block i am handling the above mentioned functionality as if i get error my catch block will call its above row's rescol value. but how many catch block i will put here because the rows are dynamic and unknown how many catch i will get executed.

    L 1 Reply Last reply
    0
    • S Satish_S

      ID col1 col2 col3 col4 rescol
      121 0 1 2 6 YES
      122 0 1 2 6 YES
      123 0 0 9 0 NULL

      Above are the Sql rows and if my function finds null for the ID=123 as 9 of col3 then i need to locate for before id's rescol and if that also find as null then i need to fetch for the above row of 121, like this till i am not getting res col as null i need to fix a loop how can i do this? In try catch block i am handling the above mentioned functionality as if i get error my catch block will call its above row's rescol value. but how many catch block i will put here because the rows are dynamic and unknown how many catch i will get executed.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      If I understand your question correctly, you can try something like this:

      SELECT TOP 1 rescol
      FROM Table1
      WHERE rescol IS NOT NULL
      AND col3 = 9
      AND [ID] BETWEEN 100 AND 200 -- Replace with appropriate values here
      ORDER BY [ID] DESC

      And remember that try catch is only for handling exceptions, it is a very worst programming practice to use it for implementing logic within your application.

      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