Return statment

Discussion in 'ASP .Net' started by JL, Dec 17, 2003.

  1. JL

    JL Guest

    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
     
    JL, Dec 17, 2003
    #1
    1. Advertising

  2. the return statement assigns the return value to the function and exits.
    so it will not.



    "JL" <> wrote in message
    news:...
    > 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
    >
    >
     
    Sedat Eyuboglu, Dec 17, 2003
    #2
    1. Advertising

  3. JL

    Hermit Dave Guest

    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

    "JL" <> wrote in message
    news:...
    > 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
    >
    >
     
    Hermit Dave, Dec 17, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. crjunk
    Replies:
    2
    Views:
    1,611
    crjunk
    Sep 3, 2004
  2. Luk
    Replies:
    2
    Views:
    326
    Andrew Thompson
    Feb 10, 2004
  3. Bill Sneddon
    Replies:
    2
    Views:
    1,219
    Bill Sneddon
    Jun 28, 2003
  4. jesusR
    Replies:
    1
    Views:
    338
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 11, 2006
  5. Jim in Arizona

    if statment based on elapsed time ..

    Jim in Arizona, Dec 14, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    372
    Rad [Visual C# MVP]
    Dec 15, 2006
Loading...

Share This Page