I'm trying to create a sub that can be called from various places in my code. It will interrogate the database and return a datatable. Now I want an optional ID parameter in the sub, which gets passed to the database.
So I could call this:
getData(536) which would return the database row with ID 536
Or I can call:
getData() which should return every row
The problem is that in Visual Studio I get the following error:
BC31405: Optional parameters cannot have structure types.
Is my approach possible to implement? I know I can remove the optional keyword and call getData(Nothing) but I'd like to know the alternatives if there are any!
Protected Sub getData(Optional ByVal Id as Nullable(Of Integer)) As DataTable