Frage

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.

War es hilfreich?

Lösung

Try this:

SELECT * FROM Person 
WHERE (? IS NULL AND Name IS NULL) OR Name = ?
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top