0

I don't know if its possible to have IIF expression that if its null or '' something like it would set a default value then if it have its own value it will retain

dtexample.Columns["tagForSomething"].Expression = "iif(tagForSomething = '',0,tagForSomething )";

I tried this things but it causes an error

For last note, as much as possible i don't want to use foreach code for this imagine having hundreds and thousands in your data table.

So I'm hoping to use the expression in data column

cdhowie
  • 158,093
  • 24
  • 286
  • 300
  • What DAL/ORM are you using here? Tagging your question with that would be helpful. – cdhowie Aug 22 '19 at 01:58
  • I'm so sorry I'm not familiar with the term you use, may you enlighten me with this? – Richard Mark Bonifacio Aug 22 '19 at 01:59
  • [DAL](https://en.wikipedia.org/wiki/Data_access_layer) and [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping) – Ken White Aug 22 '19 at 02:09
  • Looks like [ADO.NET](https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8) – cdhowie Aug 22 '19 at 02:51
  • I don't see anything wrong with this expression. You said that it "causes an error" -- what error? – cdhowie Aug 22 '19 at 02:53
  • Think you need to suround you fieldnames with [] iif([tagForSomething] = '',0,[tagForSomething] ) – Hursey Aug 22 '19 at 03:02
  • This is the error message given if i use the argument System.ArgumentException: 'Cannot set Expression property due to circular reference in the expression.' – Richard Mark Bonifacio Aug 22 '19 at 03:28
  • I don't think there will be any changes if I add [] in the column names - It is an expression after all – Richard Mark Bonifacio Aug 22 '19 at 03:30
  • [this](https://stackoverflow.com/questions/19325064/how-do-i-use-if-else-or-case-in-datacolumn-expression) could help – Syafiqur__ Aug 22 '19 at 03:47
  • I've seen that one but what I want is if it detects that the column has value it will retain but if its null or empty it will give a default value. – Richard Mark Bonifacio Aug 22 '19 at 04:00
  • 2
    I think you should add your Expression to a new column ... not to the column you use inside your Expression ... I don't think a recursive Expression like yours is supported. – PrfctByDsgn Aug 22 '19 at 08:05
  • @RichardMarkBonifacio On second glance, the recursive error makes sense. You can't have the projection of the `tagForSomething` column depend on `tagForSomething`, that doesn't make sense. – cdhowie Aug 22 '19 at 14:38

0 Answers0