Next please
14 Jun 2006
This is a simple thing, but it caught me out briefly. I have some SQL that returns
3 results
SELECT * FROM table
WHERE field1
= @param1
SELECT * FROM table
WHERE field2
= @param2
SELECT * FROM table
WHERE field3
= @param3
Then in my Data Access Layer I do the usual
while (dr.Read())
{
CustomObject obj = this.PopulateCustomObject(dr);
}
but this was only returning the first SELECT statements result. To get around
this and return all the data I'd ever want you have to wrap this in a do...while loop>
do
{
while (dr.Read())
{
CustomObject obj = this.PopulateCustomObject(dr);
if (obj
!= null)
{
objects.Add(obj);
}
}
}
while (dr.NextResult());
>