datareader.close() after return ??

G

Guest

Hi,

I have a function....

private bool myfunction()
{
SqlDataReader myReader = CommandObject.ExecuteReader();
if (myReader.HasRows)
return true;
else
return false;
myReader.close();
}

I want to know would the datareader be closed even after the 'return'
statement?

Thnx
 
S

sloan

Your answer is no.

return means return.
try this


private bool myfunction()
{

bool returnValue = false;
try
{
SqlDataReader myReader = CommandObject.ExecuteReader();
if (myReader.HasRows)
returnValue =true;

}
finally
{
if(null!=myReader)
{
myReader.close();
}
}

return returnValue ;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top