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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Why the exception "Object reference not set to an instance of an object." occurs?

Why the exception "Object reference not set to an instance of an object." occurs?

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

    Hi, I have a question, I very often get exceptions like: Object reference not set to an instance of an object. Why does it occur? for exmaple in this code: SDSCheckUser.SelectCommand = "SELECT [newuser] FROM [Users] WHERE [username] = "+username; DataView view1 = (DataView)SDSCheckUser.Select(DataSourceSelectArguments.Empty); bool newuser = (bool)view1.Table.Rows[0].ItemArray[0]; Thanx

    C D 2 Replies Last reply
    0
    • H hurrem

      Hi, I have a question, I very often get exceptions like: Object reference not set to an instance of an object. Why does it occur? for exmaple in this code: SDSCheckUser.SelectCommand = "SELECT [newuser] FROM [Users] WHERE [username] = "+username; DataView view1 = (DataView)SDSCheckUser.Select(DataSourceSelectArguments.Empty); bool newuser = (bool)view1.Table.Rows[0].ItemArray[0]; Thanx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      It means one of your casted objects returned null. You keep getting it because the code is poor - it should always check return values.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • H hurrem

        Hi, I have a question, I very often get exceptions like: Object reference not set to an instance of an object. Why does it occur? for exmaple in this code: SDSCheckUser.SelectCommand = "SELECT [newuser] FROM [Users] WHERE [username] = "+username; DataView view1 = (DataView)SDSCheckUser.Select(DataSourceSelectArguments.Empty); bool newuser = (bool)view1.Table.Rows[0].ItemArray[0]; Thanx

        D Offline
        D Offline
        daniel__c
        wrote on last edited by
        #3

        could be because if there is no user that matches the username there won't be any data at Table.Rows[0].ItemArray[0]....well that seems the most likely anyways.

        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