0

I need to update the DB also when a value in excel column is null:

CheckIntColumn(fileRow[ConstDBRow.STATUS].ToString().Trim(), membersRow.AnotherPremiumType.ToString().Trim(), "AnotherPremiumType");

But I am getting exception "Object reference not set to an instance of an object" when the column is null. and

?? string.Empty.Trim() 

is not working.. what should I do?

  • 1
    something is `null`, we can't tell you which, but: try `fileRow`, try `ConstDBRow`, try the `.ToString()` on that, try `membersRow`, try `membersRow.AnotherPremiumType`, try the `ToString()` on that. Something is null, and we can't tell you which. – Marc Gravell Apr 04 '19 at 06:55
  • @MarcGravell the ```fileRow[ConstDBRow.STATUS]``` is null, and when coding ```.ToString().Trim()``` on null is throwing exception – Tzip Perkal Apr 04 '19 at 07:01
  • well, yes; calling `.ToString()` on a `null` will indeed throw an exception. So... don't do that? – Marc Gravell Apr 04 '19 at 08:39
  • @MarcGravell how can I check in the same line is null - don't Trim() and if the value not null to trim – Tzip Perkal Apr 04 '19 at 09:46
  • a lazy way would be `fileRow?[ConstDBRow.STATUS]?.ToString()?.Trim()` – Marc Gravell Apr 04 '19 at 09:56

0 Answers0