문제

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.

도움이 되었습니까?

해결책

Try this:

SELECT * FROM Person 
WHERE (? IS NULL AND Name IS NULL) OR Name = ?
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top