How to detect a null value

  • Thread starter Thread starter keithb
  • Start date Start date
K

keithb

What is the correct syntax to detect whether a DataTable Row.ItemArray
element is a null value?

using:

if (row.ItemArray == null )

does not seem to work.

Thanks,

Keith
 
That should test for null ok. Sure it is not empty (i.e.
row.ItemArray.Length == 0 )?

--
William Stacey [MVP]

| What is the correct syntax to detect whether a DataTable Row.ItemArray
| element is a null value?
|
| using:
|
| if (row.ItemArray == null )
|
| does not seem to work.
|
| Thanks,
|
| Keith
|
|
 
What is the correct syntax to detect whether a DataTable Row.ItemArray
element is a null value?

Database NULL values are represented by the DBNull type, so try

if (row.ItemArray == DBNull.Value )


Mattias
 
Hi Keith,

for DataTables and DataRows you can use System.DbNull.Value for
comparison. This will surely work.
 
keithb said:
What is the correct syntax to detect whether a DataTable Row.ItemArray
element is a null value?

using:

if (row.ItemArray == null )

does not seem to work.


As others have said, you can compare to DBNull.Value. Another option is to
call Convert.IsDBNull(row.ItemArray).
 
Back
Top