On Nov 4, 5:23*am, Branco Medeiros <branco.medei...@gmail.comwrote:
>
Would you mind providing examples of the kind of SQL you're thinking
of using?
OK, some examples. This is not from working code so forgive any errors
but it should demonstrate the point.
say we have a select statement for a table adaptor query
("FillBySelected") in a dataset:
SELECT RecordID, Field1, Field2, Field3 FROM MyTable
WHERE (Field1 = @Filter1 OR @Filter1 IS NULL)
AND (Field2 = @Filter2 OR @Filter2 IS NULL)
AND (Field3 = @Filter3 OR @Filter3 IS NULL)
(I know the query can be written differently but I think the above is
the most readable)
then in code we have:
dset.MyTableTableAdaptor.FillBySelected(dset.MyTab le, intValue1,
intValue2, intValue3)
The problem is that although the query can accept null values it is
difficult to pass in null values without first having a complex series
of statements to determine whether to pass a variable value or just
null. ...
Besides, I'm using VB express 2008 here (no SP1) and I can assign
nullable values to parameters without problem. *But* if one of the
values is Nothing, when I execute the command an error is raised to
the lines of "the parameter ?_xx doesn't have a default value" (I'm
testing this on an Access database, and the error comes from the Jet
engine itself, not from inside .Net).
I think if the query parameter is set to accept null values then it
will accept "Nothing" as an argument but whether we pass Nothing or
DBNull is not really the point. The main question is how to avoid
having to test whether each variable is null or not and send a
different value. Even with just three arguments the number of
permutations makes this approach impractical.
I hope I have explained the problem adequately. As I said in the
original post, I can't help thinking I am missing something fairly
fundamental as I can't be the first person to come across this
challenge (and I had hoped nullable types would provide the answer but
having to test for "HasValue" returns us to the same problem). May be
I just need to write the query differently.
Any help greatly appreciated.