Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DBNull' #6

Open
FoggyFinder opened this issue Jun 28, 2020 · 0 comments

Comments

@FoggyFinder
Copy link

Call of dr.IsDBNull throws InvalidCastException.

MCVE
Replace printUser function from the Sample with one below:

let printUser (dr: IDataRecord) =
    let id = (dr?id).Value
    let name = (dr?name).Value
    let address = 
        let ai = dr.GetOrdinal("address")
        if dr.IsDBNull ai then None
        else dr.GetString(ai) |> Some
        |> function
        | None -> "No registered address"
        | Some x -> x
    printfn "Id: %d; Name: %s; Address: %s" id name address
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DBNull'.
   at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\prim-types.fs:line 598
   at FsSqlImpl.DictDataRecord.System-Data-IDataRecord-IsDBNull(Int32 i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant