Checking for null when querying a datatable or dataview in ASP.Net (VB)

You can check for null when applying a select or a filter to a datatable or dataview it is easy to filter by a field that is equal to something, but much more difficult to check if it is null.

For example (dataview):

        Dim dv As DataView = Db.GetData("uspDatabaseMenuiser_Select").Tables(0).AsDataView
        dv.RowFilter = "ParentMenuID = 0"
        dv.Sort = "MenuTitle ASC"
          

As you can see from the rowFilter we are getting where ParentMenuID = 0, but what if we want to check if ParentMenuID is null?

        Dim dv As DataView = Db.GetData("uspDatabaseMenuiser_Select").Tables(0).AsDataView
        dv.RowFilter = "IsNull(ParentMenuID, '') <> ''"
        dv.Sort = "MenuTitle ASC"


	

Leave a Reply