gpt4 book ai didi

c# - 如何在 DataColumn.Expression 中使用 IF/ELSE 或 CASE?

转载 作者:太空狗 更新时间:2023-10-29 22:19:15 29 4
gpt4 key购买 nike

我有一个包含 1 列的表格:'Status'我想添加另一个名为“Action”的列,其值如下:if Status = 'Yes' Then Action = 'Go',否则,Action = 'Stop'。我使用以下代码添加到“操作”列中,但它不起作用:

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

最佳答案

您要查找的表达式是:

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

DataTable 不支持标准 SQL CASE 语句,也不支持“IF...ELSE”语句。您必须使用 inline-if 函数:IIF

参见 DataColumn.Expression Property (MSDN)

关于c# - 如何在 DataColumn.Expression 中使用 IF/ELSE 或 CASE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19325064/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com