Question

var dbParameter = command.CreateParameter(); 
dbParameter.Name = "myParam";
dbParameter.Value = DBNull.Value;
command.Parameters.Add(dbParameter);

sql is like this:

select * from Person where Name is ?

Get an error:

An exception of type 'InterSystems.Data.CacheClient.CacheException' 
occurred in InterSystems.Data.CacheClient.dll but was not handled in user code

Additional information: [SQLCODE: <-1>:<Invalid SQL statement>]

[Location: <Prepare>]
[%msg: < NULL expected, : found^select * from Person where Name is :%qpar>]

When the query is changed to where Name = ? and a value other than DBNull.Value is set, then there is no error.

Was it helpful?

Solution

Try this:

SELECT * FROM Person 
WHERE (? IS NULL AND Name IS NULL) OR Name = ?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top