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. General Programming
  3. C#
  4. ADO Null Referance

ADO Null Referance

Scheduled Pinned Locked Moved C#
database
4 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.
  • S Offline
    S Offline
    Steve Severance
    wrote on last edited by
    #1

    I have an SqlCommand AuthUser which call a sproc in a database. When I call execute scalar it produces a NullReferanceException. Code below. Thanks. private bool CustomAuthenticate(string username,string password) { AuthUser.Connection = Global.sqlConnection; AuthUser.Parameters[0].Value = username; AuthUser.Parameters[1].Value = password; long ret = (long)AuthUser.ExecuteScalar();//Crashes here return (ret > 0); } Steve Not all who wander are lost...

    P 1 Reply Last reply
    0
    • S Steve Severance

      I have an SqlCommand AuthUser which call a sproc in a database. When I call execute scalar it produces a NullReferanceException. Code below. Thanks. private bool CustomAuthenticate(string username,string password) { AuthUser.Connection = Global.sqlConnection; AuthUser.Parameters[0].Value = username; AuthUser.Parameters[1].Value = password; long ret = (long)AuthUser.ExecuteScalar();//Crashes here return (ret > 0); } Steve Not all who wander are lost...

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #2

      I'm kinda guessing that your stored procedure is returning null....:rolleyes:

      S 1 Reply Last reply
      0
      • P Philip Fitzsimons

        I'm kinda guessing that your stored procedure is returning null....:rolleyes:

        S Offline
        S Offline
        Steve Severance
        wrote on last edited by
        #3

        ok...Thanks. Is there a way that I can tell? Steve Not all who wander are lost...

        N 1 Reply Last reply
        0
        • S Steve Severance

          ok...Thanks. Is there a way that I can tell? Steve Not all who wander are lost...

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          Steve Severance wrote: ok...Thanks. Is there a way that I can tell? Yes, not sure if you have tried this, but when you load up SQL Server Enterprise Manager you can run stored procedures from within the Query Analyser tool. Keep in mind that your stored procedure may return results, it may even return multiple results, however the ExecuteScalar() method will only extract the first column which could be null in your case. You may wish to consider using the ExecuteReader() method or changing your stored procedure to check for null values. Nick Parker


          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