On Fri, 05 Sep 2014 12:08:33 +0100, Scott Morgan <bl...@blueyonder.co.uk>
wrote:
> Am I missing a trick here? I'm reading from a BLOB SUB_TYPE 1 column
> using the following:
> 
> FbDataReader reader = /* blah */
> string text = (string)reader["LONG_TEXT"];
> 
> It's okay when there is data, but if the column happens to be NULL I get
> an error ("Unable to cast object of type 'System.DBNull' to type
> 'System.String'"), where I'd ideally like to get a plain null.
> 
> FbDataReader.GetString doesn't work for me as it just returns ""
> 
> So I'm left with a messy lump of GetOrdinal, IsDBNull, code. There's got
> to be a better way, but I'm not seeing it.

A quick workaround is to use:

string text = reader["LONG_TEXT"] as string;

This will perform the cast, but return null if the cast failed.

Mark

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to