Tag Archives: C#

ODAC Assigning DBNull.Value to paramater

Here we go, null is not an instance of any type, it is an invalid reference.Whereas, System.DbNull.Value, is a valid reference to an instance of System.DbNull
that represents nonexistent (e.g. NULL) values in the database.

(System.DbNull is a singleton and System.DbNull.Value gives you a reference to the single instance of that class)

The keyword null represents an invalid reference. The class System.DbNull represents a nonexistent value in a database field.

// Assigning Null value to Procedure Parameter

OracleParameter pram_IN_1 = new OracleParameter("pPACKAGE_NAME", OracleDbType.Varchar2);
pram_IN_1.Direction = ParameterDirection.Input;
pram_IN_1.Value = strPackageName != null ? strPackageName : (object)DBNull.Value;
cmd.Parameters.Add(pram_IN_1);

//

C#.Net Common Variable Types

The chart below details most of the common variable types, as well as their size and possible values.

C# Type .Net Framework (System) type Signed? Bytes Occupied Possible Values
sbyte System.Sbyte Yes 1 -128 to 127
short System.Int16 Yes 2 -32768 to 32767
int System.Int32 Yes 4 -2147483648 to 2147483647
long System.Int64 Yes 8 -9223372036854775808 to 9223372036854775807
byte System.Byte No 1 0 to 255
ushort System.Uint16 No 2 0 to 65535
uint System.UInt32 No 4 0 to 4294967295
ulong System.Uint64 No 8 0 to 18446744073709551615
float System.Single Yes 4 Approximately ±1.5 x 10-45 to ±3.4 x 1038 with 7 significant figures
double System.Double Yes 8 Approximately ±5.0 x 10-324 to ±1.7 x 10308 with 15 or 16 significant figures
decimal System.Decimal Yes 12 Approximately ±1.0 x 10-28 to ±7.9 x 1028 with 28 or 29 significant figures
char System.Char N/A 2 Any Unicode character (16 bit)
bool System.Boolean N/A 1 / 2 true or false