The reason for this is that null values from the database are represented with
DbNull[
^] values in memory. You need to add a conditional around the place where you add
DataGridView1(j, i).Value
to the total, deciding what to do when you see a null value (for example, skip it). There is an example at the above link showing you how to do it.