469,613 Members | 1,927 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

How to detect a null value

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

using:

if (row.ItemArray[i] == null )

does not seem to work.

Thanks,

Keith
Mar 17 '06 #1
4 3899
That should test for null ok. Sure it is not empty (i.e.
row.ItemArray[i].Length == 0 )?

--
William Stacey [MVP]

"keithb" <kb******@dslextreme.com> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
| What is the correct syntax to detect whether a DataTable Row.ItemArray
| element is a null value?
|
| using:
|
| if (row.ItemArray[i] == null )
|
| does not seem to work.
|
| Thanks,
|
| Keith
|
|
Mar 17 '06 #2
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[i] == DBNull.Value )
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 17 '06 #3
Jay
Hi Keith,

for DataTables and DataRows you can use System.DbNull.Value for
comparison. This will surely work.

Mar 18 '06 #4
keithb wrote:
What is the correct syntax to detect whether a DataTable Row.ItemArray
element is a null value?

using:

if (row.ItemArray[i] == 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[i]).
--
Tom Porterfield

Mar 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robb Gilmore | last post: by
3 posts views Thread by charliewest | last post: by
2 posts views Thread by shankwheat | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.