C# .NET - how to skip recod in datareader while loop and read next record

Asked By mani on 26-Dec-11 09:28 AM
hi. ,i am using while loopt to read record row by row..
and i need to skip some record based on my some condition and goto next record and continue,,
is it possible in datareader whilloop????any help
Riley K replied to mani on 26-Dec-11 10:28 AM

Use like this 

while(Reader.Read())
{
 
if(Reader["ID"] != 0)
{
// do something you want
 
}
else
continue;
}

in if write the condition you want , you can skip the else portion too , if the condition doesnot meet it will automatically goes to next record skipping the current.




Regards
Web Star replied to mani on 26-Dec-11 11:23 PM

while(rdr.Read())
{
 if(rdr["Status"] !="Pending")
{
// do your task which you need if the staus in not pending 
}
}
Jitendra Faye replied to mani on 26-Dec-11 11:58 PM
Try like this-

while(Reader.Read())
{
 
if(condition)
{
  //skip 
  continue; 
}
}