|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
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
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:
System.Nullable<System.DateTime> nullValue = new System.Nullable<System.DateTime>(); northwindDataSetOrdersTableAdapter.FillByShippedDate(northwindDataSet.get_Orders(), nullValue);
Setting the AllowDbNull Property
To enable a query to accept null values
In the Dataset Designer, select the TableAdapter query that needs to accept null parameter values.
Select Parameters in the Properties window and click the ellipsis (…) button to open the Parameters Collection Editor.
Select the parameter that allows null values and set the AllowDbNull property to true.