Bagikan melalui


How to: Handle Null Values in a DataColumn

In a typed dataset, you can control the representation of columns that contain null values. This behavior is only available when retrieving column values through their typed accessors. If you retrieve the value by means of the table's row index or column index, you will not be able to set the return value. The reason for this is that the logic to return this value is built into the property setter of the specific data column in the generated dataset class.

To set the value to return when a DataColumn's value is null

  1. Open the dataset in the Dataset Designer.

  2. Select a column in a data table.

  3. In the Properties window, select the NullValue property.

  4. Do one of the following:

    • From the drop-down list, select the appropriate value:

      Value

      Description

      (Empty)

      Returns null values String.Empty.

      (Nothing)

      Returns null values as DBNull.

      (Throw exception)

      Null values throw an Exception.

      -or-

    • Set the property to any custom value valid for that column's data type. For example, if you specify the string No Value, for a column with a data type of String, any records that contain null values in that column will display "No Value".

See Also

Concepts

Working with Null Values in TableAdapters

Reference

String.Empty

DataSet

DataColumn