SafeDataReader

SafeDataReader

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


georgeb posted on Tuesday, July 25, 2006

What is the best way to determine if the safedatareader contains any data (rows) of information?

Based on criteria a BO tries to fetch its data from the database. If the criteria are wrong then no data is returned and that brakes the code.

The SqlDataReader has a HasRows public property that solves the problem.

Any suggestions are more than welcome.

glenntoy replied on Tuesday, July 25, 2006

Use the SafeDataReader.Read() <-- returns true if there are records read from the database otherwise false.

 

georgeb replied on Tuesday, July 25, 2006

Thanks!

RockfordLhotka replied on Tuesday, July 25, 2006

Keep in mind however, that normal CSLA designs assume that DataPortal_Fetch() will raise an exception if data isn't found. That exception flows back to the UI so the UI can tell the user that no data was there.

If you do NOT raise an exception from DataPortal_Fetch(), then you'll have to come up with your own mechanism for notifying the UI that no data was found. Various alternative solutions were discussed in another thread a month or two ago - including the idea of returning a "null object" - not null, but a special empty object of some sort. I didn't pay close attention to the implementation, but you may find info by searching through the forum.

georgeb replied on Wednesday, July 26, 2006

Thank you for the suggestions. I will follow the idea of "null object". It is best suited in my project for getting a fast answer if an object exists and if exists retrieve the object all with one operation.  

Copyright (c) Marimer LLC