Don't forget that. Null != DBNull.value. If you pass null to an sql parameter, it is the default value. You need to escape null values and pass dbnull in it's place.
Davy "When all you have is a hammer, every problem looks like a nail." I feel much the same way about xml -----Original Message----- From: "Greg Keogh" <[email protected]> Sender: [email protected] Date: Sun, 30 Jan 2011 10:37:26 To: 'ozDotNet'<[email protected]> Reply-To: ozDotNet <[email protected]> Subject: RE: Entity SQL null parameters Hi Neil I thought I had this Entity SQL problem solved, but two steps forward and one backward (as usual). You can't construct an ObjectParameter with a name and null value, you have to give a type like this: ObjectParameter param = new ObjectParameter("MyNum", typeof(int)); I can understand that that parameter must be given a type before it's added. This leaves the value null and it allowed me to use the parameters with null values like this inside a WHERE clause: ((@OwnId IS NULL) OR (i.OwnId=@OwnId)) AND ((@MedId IS NULL) OR (v.MedId=@MedId)) This is just what I want, a large general purpose WHERE clause that deals nicely with null parameters. I was all excited, but the parameters so far were all integers, and then I appended this string parameter to the clause: ... AND ((@Title IS NULL) OR (v.Title=@Title)) This causes a terrible SQL CE error I experienced last year when writing plain ADO.NET for SQL CE and I did not add the parameters in exactly the correct way: System.Data.SqlServerCe.SqlCeException The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ] So I'm stuck in a log jam again and searching the web. Greg
