fsprojects / ExcelProvider

This library is for the .NET platform implementing a Excel type provider.
http://fsprojects.github.io/ExcelProvider/
The Unlicense
141 stars 51 forks source link

Sample documentation missing for handling DBNull #8

Closed 7c6f1568-555e-42a8-aff6-9045799c8b86 closed 10 years ago

7c6f1568-555e-42a8-aff6-9045799c8b86 commented 10 years ago

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

Thank you.

JohnDoeKyrgyz commented 10 years ago

Issue has been fixed on revision: a48e9adc5b2fa5357d2db98cad9f90f4835d5b64. Released on NuGet as version 0.1.2.

Thanks for reporting this!