SafeDataReader HasValue

SafeDataReader HasValue

Old forum URL: forums.lhotka.net/forums/t/4721.aspx


qing02051981 posted on Monday, April 21, 2008

Why doesn't the SafeDataReader has the property HasValue like SqlDataReader does?

How can I check if there are records being return from a select procedure?

tmg4340 replied on Monday, April 21, 2008

Are you talking about the "HasRows" property?  Because I don't see a "HasValue" property on the SqlDataReader either...

In any event, the SafeDataReader is a wrapper class that implements the IDataReader interface.  The internal variable that it keeps is also an IDataReader.  IDataReader does not have the "HasRows" property, so it's not on the class.

You could create your own subclass of SafeDataReader and add the properties that you need, but you would need to be sure and check that the wrapped DataReader supports them.  For example, presuming you're working in at least .NET 2.0, the "HasRows" property is on the DbDataReader class, which most MS readers derive from.  You could probably make an assumption in your subclass and just cast the protected property to a DbDataReader, but to be safe you should probably check to make sure you can do the cast first.

HTH

- Scott

Copyright (c) Marimer LLC