I’m using the VS2010 DataSet designer to make some select queries with optional parameters similar to this:
SELECT CustomerID, FirstName, JoinDate, etc
FROM tblCustomers
WHERE (
(@CustomerID IS NULL OR CustomerID = @CustomerID) AND
(@FirstName IS NULL OR FirstName = @FirstName) AND
(@JoinedBefore IS NULL OR JoinDate < @JoinedBefore) AND
(@JoinedAfter IS NULL OR JoinDate > @JoinedAfter) AND
.. etc ..
)
The inference for these properties data-types and allow DB null is almost always wrong. I end up with string types set for date time and vice versa. Over half the fields are always marked as non-null.
That obviously wreaks havoc on my queries. I can manually change these inference’s, but every time I have to update the TableAdapter, it resets them all to what it thinks is best! Anyone know how to either a) get the inferences right, or b) override them in a permanent way?
It seems VS infers the data type based on the first occurrence of the parameter in the query. Because I put my @Parater IS NULL OR… first, that confused the designer and caused it to infer wrong a lot of the time. I swapped the order of my query and now it infers perfectly: