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. How to Check Null for records returned?

How to Check Null for records returned?

Scheduled Pinned Locked Moved ASP.NET
questionhelptutorial
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.
  • N Offline
    N Offline
    Nickson
    wrote on last edited by
    #1

    Hi, When i try to try to use the ExecuteScalar method, e.g. myValue = cmd.ExecuteScalar(), I get an error when the result is null. How can i avoid this? rgds, Nickson

    K 1 Reply Last reply
    0
    • N Nickson

      Hi, When i try to try to use the ExecuteScalar method, e.g. myValue = cmd.ExecuteScalar(), I get an error when the result is null. How can i avoid this? rgds, Nickson

      K Offline
      K Offline
      kaschimer
      wrote on last edited by
      #2

      wrap the ExecuteScalar method call in a try/catch and take appropriate actions if an exception is caught (in the case of no record returned) If you mean that you get an error when you try to do something with myValue, you can check to see if it is null: if(myValue != DBNull.Value) { etc. } RabidK

      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