Problem with ASP.Net Null Values

Asked By 20 points N/A Posted on -
qa-featured

Hi! I am intermediate in ASP. Net and in some cases of using the NULL values, I am getting an error stating that “Object reference not set to an instance of an object”. I don’t get why then null value is used and then I got that accidentally. The next thing i know is, it is moved into database without tables with an error message appeared. Please see the picture below for your reference.

Object reference not set to an instance of an object

"Object reference not set to an instance of an object- Microsoft Internet Explorer
Server Error in '/Touchpaper.Framework.Web' Application.
Object reference not set to an instance of an object "

Any solution is greatly helpful.

Thank you.

SHARE
Best Answer by Joceyn mathew
Best Answer
Best Answer
Answered By 0 points N/A #151364

Problem with ASP.Net Null Values

qa-featured

In ASP.Net the null values refer to the references that are not created objects, means not allocated memory but still they are being used as if they are objects. This means that the error appears when you have created reference for a type of class. Then you are no longer created the object using then new method. The new method allocates memory for the object. But still then the reference is being treated as if this is an object.

The entire jest is that you have missed a new operator in the entire code. You have created a reference to an object but not allocated memory using the new operator.

Thanks.

Answered By 0 points N/A #151365

Problem with ASP.Net Null Values

qa-featured

Hi!

Need some more information regarding you're issue. In case if you are trying to do some operations with variables try to check whether the value is null or not before doing the operation then you can avoid the above exception.

if(you' r_variable != null)

{ // Perform the operation }

If you want to pass null values to the database use something like similar to following coding since there are many ways of passing parameters to the database.

SqlParameter[] param = new SqlParameter[1];

param[0] = new SqlParameter("@variable", SqlDbType.VarChar);
param[0].Value = DBNull.Value;

Try to post some more coding. So that i can look in to you're actual scenario.

 

 

Login/Register to Answer

Related Questions