none
Object reference not set to an instance of an object. Use the "new" keyword to create an object instance RRS feed

  • Question

  • I have the following piece of code which when I run gives me the above error. What could be the problem:

    if (rsAccts.Read())
            {
                if (rsAccts["UserID"].ToString() != Session["UserID"].ToString())
                {
                    lblMessageLine.ForeColor = System.Drawing.Color.Red;
                    lblMessageLine.Text = "The specified code has been used by a different user";
                    rsAccts.Close();
                    rsAccts = null;
                    return;
                }
                
            }

    Wednesday, November 14, 2012 9:57 AM

Answers

  • Hi

    Try this to to handle error.

    if(rsAccts !=null)
    {
      if (rsAccts.Read())
      {
        // you code
      }
    }


    PS.Shakeer Hussain

    • Marked as answer by johnspax Wednesday, November 14, 2012 10:34 AM
    Wednesday, November 14, 2012 10:17 AM

All replies