Uzma Nikhath

Uzma Nikhath

  • NA
  • 1
  • 8.6k

Object reference error

Oct 7 2010 12:50 AM
Hi,

I'm trying to create a new user registration page in ASP.NET. I'm stuck with this error "Object reference not set to an instance of an object." and i couldn't figure it out  where I'm going wrong

the try block code is here
try
        {
            SqlConnection objConnection = null;
            SqlCommand objCommand = null;
            objConnection = GetConnection();
            objConnection.Open();
            objCommand = GetCommandobj(objConnection);
            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "CheckforDuplicates";


            SqlParameter ObjParam1 = new SqlParameter("@Username", SqlDbType.NVarChar);
            ObjParam1.Value = UserName;
            SqlParameter ObjParam2 = new SqlParameter("@Firstname", SqlDbType.NVarChar);
            ObjParam2.Value = strFname;
            SqlParameter ObjParam3 = new SqlParameter("@Lastname", SqlDbType.NVarChar);
            ObjParam3.Value = strLname;
            SqlParameter ObjParam4 = new SqlParameter("@Emailadd", SqlDbType.NVarChar);
            ObjParam4.Value = stremailadd;
            SqlParameter ObjReturnParam = new SqlParameter("@Duplicates", SqlDbType.Int);
            ObjReturnParam.Direction = ParameterDirection.ReturnValue;
            objCommand.ExecuteNonQuery();
            if (Int32.Parse(ObjReturnParam.Value.ToString()) > 0)
            {
                Response.Write("UserName already exists or you are already a registered user!");
                return false;
            }
            else
            {
                return true;
            }
            objConnection.Close();

this is the line where it shows the error:

if (Int32.Parse(ObjReturnParam.Value.ToString()) > 0)

Any help and suggestion is appreciated.

THanks

Answers (2)