Freigeben über


Working with Null Values in TableAdapters

TableAdapter parameters can be assigned null values when you want to query for records that have no current value. For example, consider the following query that has a ShippedDate parameter in its WHERE clause:

SELECT CustomerID, OrderDate, ShippedDate

FROM Orders

WHERE (ShippedDate = @ShippedDate) OR

(ShippedDate IS NULL)

If this were a query on a TableAdapter, you could query for all orders that have not been shipped with the following code:

OrdersTableAdapter.FillByShippedDate(NorthwindDataSet.Orders, Nothing)
ordersTableAdapter.FillByShippedDate(northwindDataSet.Orders, null);

Setting the AllowDbNull Property

To enable a query to accept null values

  1. In the Dataset Designer, select the TableAdapter query that needs to accept null parameter values.

  2. Select Parameters in the Properties window and click the ellipsis () button to open the Parameters Collection Editor.

  3. Select the parameter that allows null values and set the AllowDbNull property to true.

See Also

Tasks

How to: Create TableAdapters

How to: Create TableAdapter Queries

Walkthrough: Creating a TableAdapter with Multiple Queries

Concepts

TableAdapter Overview

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Connecting to Data in Visual Studio