tags:

views:

31

answers:

1

are you know the difference between this two condition

1

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

}
}

2

while(reader.read())
{
if(reader.hasrows())
{
}
}
+2  A: 

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
@Zachary Dear are you sure ! any reference to clear confusion
steven spielberg
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