Return statment

  • Thread starter Thread starter JL
  • Start date Start date
J

JL

Hi all,

I have a self defined function at following

Function testing()
if a < b then
return a
else
return b
end if
sqlCon.close()

Based on above function, does the system will excute the "sqlCon.close()"
statement after "end if"? or quit the function when excuted the "return"
statement.

Thanks a lot
 
the return statement assigns the return value to the function and exits.
so it will not.
 
try putting the sqlCon.close() in the finally statement

SqlConnnection sqlCon = new SqlConnection("connnection string")
try
{
SqlCommand sqlCommand = new SqlCommand("command name", sqlCon);
// do your processings

your conditional statements
if (a < b)
return a;
else
return b;
}
finally
{
sqlCon.close()
sqlCon.Dispose()
}

the close will then be called no matter what..

HTH

HD
 
Back
Top