Object cannot be cast from DBNull to other types - Help!

Good afternoon/evening/morning,

I have tried parsing through every relevant forum post on here regarding this issue, but none of them are specific to what I am dealing with, so here goes:

I am trying to do some simple math with datatable rows, and I keep getting the “Object cannot be cast from DBNull to other types” error.

I am doing a “For Each Datatable Row” activity with the following datatable:
DBNull_post
Column0 = Int32
Column1 = Double
Column2 = Double
Column3 = Double

And for each row, i am trying to do some simple division:
DBNull_post_2

Also doing division like this:
DBNull_post_3

I have tried CDbl as well, but still getting errors.

On another automation I have done, I used a method by where the “build datatable” activity had all of the columns as strings for the numerical values, and I used the following script to sum all of the values in a certain column:

Convert.ToString(buildData.AsEnumerable().Sum(Function(row)
Convert.ToDouble(If(String.IsNullOrEmpty(Convert.ToString(row("Ext MRC"))),"0",Convert.ToString(row("Ext MRC"))))))

So something is telling me the solution to my problem is similar?

I hope someone can shed light on this - I am going on several hours of work trying to solve what should just be simple math.

Many thanks as always!

Short told ( a little bit too much simplified):
DBNull is another representation of Undefined and therefore it cannot meanfully parsed to e.g. a number

here you can sanitize by filtering out all empty rows or ommit empty rows

For detecting a DBNull have a look below when setting up a cascade of checks
grafik