The sample code I took from the documentation works fine until I have an empty cell.
let valueA = row.ColumnA
This then throws System.InvalidCastException
An unhandled exception of type 'System.InvalidCastException' occurred in sample.exe
Additional information: Unable to cast object of type 'System.DBNull' to type 'System.String'.
What is the recommended way to deal with this? I could catch the exception but this isn't very nice code?
let mutable valueA = Unchecked.defaultof<string>
try
valueA <- row.ColumnA
with ex ->
valueA <- String.Empty
The sample code I took from the documentation works fine until I have an empty cell.
This then throws System.InvalidCastException An unhandled exception of type 'System.InvalidCastException' occurred in sample.exe Additional information: Unable to cast object of type 'System.DBNull' to type 'System.String'.
What is the recommended way to deal with this? I could catch the exception but this isn't very nice code?
Thank you.