CASE or IF statement in Datacolumn.Expression

  • Thread starter Thread starter jelling
  • Start date Start date
J

jelling

Hi,

Is it possible to use a CASE or IF ELSE statement in a datacolumn
expression?

Here's what I've tried:

'standardCodeColumn.Expression = "CASE StandardsBodyID
WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
'standardCodeColumn.Expression = "CASE WHEN
StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"

But I keep getting errors like this:

Syntax error: Missing operand after 'StandardsBodyID' operator

Please help if you can. I know we can do this at the SQL View level
but its a requirement in this case to move that logic to the BLL/DAL
layer.

Thank you,

..jelling
 
Hi,

Is it possible to use a CASE or IF ELSE statement in a datacolumn
expression?

Here's what I've tried:

'standardCodeColumn.Expression = "CASE StandardsBodyID
WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
'standardCodeColumn.Expression = "CASE WHEN
StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"

But I keep getting errors like this:

Syntax error: Missing operand after 'StandardsBodyID' operator

Please help if you can. I know we can do this at the SQL View level
but its a requirement in this case to move that logic to the BLL/DAL
layer.

The Help for Expression pretty clearly explains what is legal:

<http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx>

It looks like IIF() will do what you want.
 
Back
Top