我正在尝试为 DataColumn 添加表达式,它将当前列的 bool 值更改为字符串值:
col = new DataColumn("isDirectionIn", typeof(string),
"IIF(isDirectionIn = true, 'in', 'out')");
但我总是得到一个 ArgumentException:由于表达式中的循环引用而无法设置表达式属性。
我应该怎么做才能避免这种异常?提前致谢。
最佳答案
错误消息清楚地告诉您,您在计算表达式列时引用了表达式列,因此是循环引用。
你需要做类似的事情:
col = new DataColumn("isDirectionAsString", typeof(string),
"IIF(isDirectionIn = true, 'in', 'out')");
换句话说,您不能“就地”执行该操作。您的“as string”值需要一个额外的列。
干杯
关于c# - DataColumn.Expression 属性。将当前列的 bool 值转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21879044/