---
title: "Checking for NULL values"
url: "https://osherove.com/blog/2003/7/28/checking-for-null-values.md"
canonical: "https://osherove.com/blog/2003/7/28/checking-for-null-values.html"
published: "2003-07-28T06:57:00"
updated: "2003-07-28T06:57:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "I was recently asked how to check if a DB value you have in your hands is NULL . For one, you can use the System.DBNull class's ' Value ' property to check this like so: if (myVar==DBNull.Value) Another way, is when you…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Checking for NULL values

By Roy Osherove July 28, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published July 28, 2003; technical details may be outdated.

I was recently asked how to check if a DB value you have in your hands is _NULL_.

For one, you can use the _System.DBNull_ class's '_Value_' property to check this like so:

if (myVar==DBNull.Value)

Another way, is when you have a _DataRow_ in your hands:

if(myDataRow.IsNull(myFieldName))

if(myDataRow.IsNull(myFieldIndex))

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Jul 28, 2003

    ### [DataReader.HasRows](https://osherove.com/blog/2003/7/28/datareaderhasrows.html)

- Jul 28, 2003

    ### [Filling typed datasets using Data Access Application Block v.2.0](https://osherove.com/blog/2003/7/28/filling-typed-datasets-using-data-access-application-block-v.html)

- Jul 27, 2003

    ### [C++ for programmers](https://osherove.com/blog/2003/7/27/c-for-programmers.html)

- Jul 23, 2003

    ### [Scripting .Net](https://osherove.com/blog/2003/7/23/scripting-net.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
