0

Do you know the difference between these two conditions?

1

if(reader.hasrows())
{
   while(reader.read())
   {

   }
}

2

while(reader.read())
{
   if(reader.hasrows())
   {
   }
}
demongolem
  • 9,474
  • 36
  • 90
  • 105

1 Answers1

2

Doing if/while or while/if is not necessary, since "while(reader.read())" will only return true when the reader has rows "hasrows()" and has a row to read "read()". The extra nesting has no value.

Zachary
  • 6,522
  • 22
  • 34
  • I'm assume your using something that implements IDataReader, here is the MSDN link for the Read() method. http://msdn.microsoft.com/en-us/library/system.data.idatareader.read.aspx, notice how it say's that read() only return true it it has "more" rows to read... – Zachary Jun 23 '10 at 03:05