Check it for null values.
If the cell contains a null - which is perfectly valid if the datasource is a null - then when you try to call ToString you will get an error.
So replace this:
value = dr.Cells[i].Value.ToString();
with this:
value = (dr.Cells[i].Value ?? "").ToString();
Which will replace null values with an empty string.