Share via


How to assign null value to a long or int data type in asp.net using c#

Question

Thursday, August 12, 2010 4:15 AM

I am working on asp.Net application with the backend in Oracle. I am using ODP.Net to interact with the oracle server.

I have written oracle store procedure to do DML Operation.  In the cases where I wanted to insert null values in a colum I face problem.

The problem is that in oracle tables the data type of all my Primary Key and Foreing Key tables is

Number(12). At the fron end (C#), I alwasy declare a long for any of the foreign/Primary key

Like:

long PK;

When there is a need to insert null value in the foreign key, I face problem as we can not assign null values to int/long.

 

What to do?

I wonder why it is so that we can not assign null values to INT/LONGs in C#

All replies (1)

Thursday, August 12, 2010 6:38 AM âś…Answered

Hi,

that's because they're value types instead of reference types.

If you want to put null in them you should use the nullable type equivalent like int? and long?: http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx.

Grz, Kris.