c# - Dapper How to Handle DBNull by DynamicParameter.Get -
var param = new dynamicparameters(); param.add("msgid", dbtype.int32, direction: parameterdirection.output); connection.execute(messageseloutmessageid, param, commandtype: commandtype.storedprocedure); count = param.get<int>("msgid");
by reference dapper, using code above call stored procedure output parameter - msgid. working fine in cases, there no value found stored procedure , returned output parameter value null. in these cases exception error below :
attempting cast dbnull non nullable type! note out/return parameters not have updated values until data stream completes (after 'foreach' query(..., buffered: false), or after gridreader has been disposed querymultiple)
understood mark return data type nullable avoid error code below
count = param.get<int?>("msgid");
but there other way check param.get("msgid") == null instead of using nullable data type - int?
thanks paulius, tried dynamic datatype count = param.get<dynamic>("msgid");
, work i'm looking for.
Comments
Post a Comment