Monday, November 29, 2004

Does DataReader/IDataReader has data inside ?

I guess everyone of you know this, but I just wanna write this for some soul who might be googling for this.
When we extract data into a dataset, we can simply count its rows and know if at all it contains something, but what about DataReader/IDataReader?
When you are using DataReader, .Net 1.1 brings you HasRows Property which will tell u rightaway if you have some rows to work with.
Now comes IDataReader, nothing new here :
if (!objReader.Read())
// there is no data
// there is data
// NOTE : First record has been read already!
// you are already pointing to the first record,
// so your processing which should be here has started with the
// first record
while (objReader.Read());
// keep looping till the end of data
So there you go, simple things in life put into words :D
BTW, VB.NET users pls take note.(below code are in context to the above algorithm)
As above, use the Post-Test Loop
' Processing is here and the fist record was already selected, so rock on!
Loop While (objReader.Read())
instead of the Pre-Test Loop
Do While (objReader.Read())

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

© Copyright 2005, Rohan Thomas
This Blog contains findings that are self-explored and expressions that are self-evoked. They are by no meanss representions of my employer's view.