Replace null values with 0 from a data table column using LINQ

Dear Experts,

Good Day.

I need to update a column Sales Amount and Net Amount in the data table where the values are null with a 0.00 since that column is double.

Reference Bank Invoice Bank Amount Sales Amount Difference Net Amount
4900067828 8203000073 -201780
4900067827 8203000072 -1069080
4700334343 2100003040 -2361.6
4700334342 2100003039 -2361.6
4700334341 2100003038 -2361.6
4700332997 2100002952 -26981.86
4700305131 97139650 236736.76 236921.86 185095.2
4700305052 97139652 69860 69914.62 54620.8
4700305007 97139651 80930 80993.28 63276
4700305002 97139648 157232.59 157355.52 122934
4700304999 97139649 11295.86 11304.69 8831.79

I tried something like this , however there was an error.

dtResult2.AsEnumerable.ToList.ForEach(sub(row) row(“Sales Amount”) = if (String.IsNullOrEmpty(row(“Sales Amount”).tostring),math.Round(CDBl(row(“Sales Amount”).tostring.replace(“”,“0.00”),2))))

image

Your inputs are always appreciated.

Regards,
Manjesh

Hi @manjesh_kumar

Refer to the thread below its similar to yours!

Regards

@manjesh_kumar

Check below for your reference

Invoke Code - Edit Arguments pass the datatable by direction In/Out

dtoutput.AsEnumerable.Where(Function(row) row(“Column2”).ToString.Trim.Equals(“”)).ToList().ForEach(Sub(row) row(“Column2”) = “0.00”)

Hope this may help you

Thanks

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.