I'm trying to add expression,which changes boolean value of current column to string value, for DataColumn:

col = new DataColumn("isDirectionIn", typeof(string),
                                     "IIF(isDirectionIn = true, 'in', 'out')");

But I always get an ArgumentException: Cannot set Expression property due to circular reference in the expression.

What should I do to avoid this exception? Thank in advance.

有帮助吗?

解决方案

The error message is telling you clearly that you are referencing your Expression column in the calculation of you Expression column, thus a circular reference.

You need to do something like:

col = new DataColumn("isDirectionAsString", typeof(string),
                                     "IIF(isDirectionIn = true, 'in', 'out')");

In other words, you can't do that "in-place". You need an extra column for your "as string" value.

Cheers

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top