views:

37

answers:

0

I'm in the process of updating an app to VS 2010 using EntLib 5. In the app as it stands, there are numerous instances where a dropdown list is bound to a SqlDataReader. However, before it is bound, I use the HasRows property to see if the DataReader is empty. Since the ExecuteReader method in EntLib 5.0 returns an IDataReader, to do the same thing, I need to cast the IDataReader to a RefCountingDataReader and then cast the InnerReader property to a SqlDataReader.

Using rdr As SqlDataReader = CType(CType(db.ExecuteReader("spname"), RefCountingDataReader).InnerReader, SqlDataReader)

I found this workaround online and this has been addressed in many places (including SO).

However, another alternative is to load the IDataReader into a DataTable, check the row count and then bind that to the dropdown list. Which is the better option? Or is another option optimal?

Sorry to be so long and drawn out. Any advice would be awesome.