如何在DataColumn.Expression中使用IF / ELSE或CASE? [英] How do I use IF/ELSE or CASE In DataColumn.Expression?

查看:262
本文介绍了如何在DataColumn.Expression中使用IF / ELSE或CASE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中有1列:'Status'
我想在另一列中添加'Action',其值如下:如果Status ='Yes'然后Action ='Go',否则,Action ='Stop'。我使用以下代码在操作列中添加了它,但没有用:

I have a table with 1 column: 'Status' I want to add in another column named 'Action', its value will be as follow: if Status = 'Yes' Then Action = 'Go', otherwise, Action = 'Stop'. I used this following code to add in column 'Action' but it didn't work:

myDataTable.Columns.Add("Action", typeof(string), "IF [Status] = 'Yes' THEN 'Go' ELSE 'Stop' END");


推荐答案

您要查找的表达式是:

IIF( [Status] = 'Yes', 'Go', 'Stop' )

DataTables不支持标准SQL CASE 语句,也不支持 IF ... ELSE 声明。您必须使用内联if函数: IIF

DataTables do not support standard SQL CASE statements, nor do they support "IF... ELSE" statements. You must use the inline-if function: IIF

请参见 DataColumn.Expression属性(MSDN)

这篇关于如何在DataColumn.Expression中使用IF / ELSE或CASE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆