sqlHelper exception handling

Discussion in 'ASP .Net' started by =?Utf-8?B?Ymlj?=, Oct 4, 2007.

  1. Hi,

    Calling my method below how does my page caller display the exception since
    the return type is int?

    int ret = 0;
    string spname = "sp_UpdateAd";
    try
    {
    //Retrieve the parameters from the cache
    SqlParameter[] storedParams =
    SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
    if( storedParams == null )
    {
    //Cache the parameters
    SqlParameter[] paramsToStore = new SqlParameter[]
    {

    };
    SqlHelperParameterCache.CacheParameterSet( connString, spname,
    paramsToStore );
    storedParams = paramsToStore;
    }
    ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
    spname, storedParams );
    }
    catch( Exception ex ) { throw; }
    finally{} // Do NOT dispose connection

    return ret;

    Thanks,

    --
    bic
     
    =?Utf-8?B?Ymlj?=, Oct 4, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?Ymlj?=

    sloan Guest

    I'd read this:

    http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

    since you have a "throw", the exception gets bubbled up.

    the "page" you have would probably catch the exception, and then display a
    message to the user.

    in winforms, if you don't handle the exception in the "page", your app will
    crash.

    in webforms, if you don't handle the exception in the "page", your page will
    show a nasty dotnet type exception message.


    "bic" <> wrote in message
    news:...
    > Hi,
    >
    > Calling my method below how does my page caller display the exception
    > since
    > the return type is int?
    >
    > int ret = 0;
    > string spname = "sp_UpdateAd";
    > try
    > {
    > //Retrieve the parameters from the cache
    > SqlParameter[] storedParams =
    > SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
    > if( storedParams == null )
    > {
    > //Cache the parameters
    > SqlParameter[] paramsToStore = new SqlParameter[]
    > {
    >
    > };
    > SqlHelperParameterCache.CacheParameterSet( connString, spname,
    > paramsToStore );
    > storedParams = paramsToStore;
    > }
    > ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
    > spname, storedParams );
    > }
    > catch( Exception ex ) { throw; }
    > finally{} // Do NOT dispose connection
    >
    > return ret;
    >
    > Thanks,
    >
    > --
    > bic
     
    sloan, Oct 4, 2007
    #2
    1. Advertising

  3. when I do this in my page
    lblMessage.Text = a.UpdateAdStatus( ....);
    it causes an cannot implicitly convert type 'int' to 'string' error, for
    the method has a return type of int. Are you suggesting that I simply just do
    a.UpdateAdStatus( ....);
    instead?

    Thanks,
    --
    bic


    "sloan" wrote:

    >
    > I'd read this:
    >
    > http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx
    >
    > since you have a "throw", the exception gets bubbled up.
    >
    > the "page" you have would probably catch the exception, and then display a
    > message to the user.
    >
    > in winforms, if you don't handle the exception in the "page", your app will
    > crash.
    >
    > in webforms, if you don't handle the exception in the "page", your page will
    > show a nasty dotnet type exception message.
    >
    >
    > "bic" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > Calling my method below how does my page caller display the exception
    > > since
    > > the return type is int?
    > >
    > > int ret = 0;
    > > string spname = "sp_UpdateAd";
    > > try
    > > {
    > > //Retrieve the parameters from the cache
    > > SqlParameter[] storedParams =
    > > SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
    > > if( storedParams == null )
    > > {
    > > //Cache the parameters
    > > SqlParameter[] paramsToStore = new SqlParameter[]
    > > {
    > >
    > > };
    > > SqlHelperParameterCache.CacheParameterSet( connString, spname,
    > > paramsToStore );
    > > storedParams = paramsToStore;
    > > }
    > > ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
    > > spname, storedParams );
    > > }
    > > catch( Exception ex ) { throw; }
    > > finally{} // Do NOT dispose connection
    > >
    > > return ret;
    > >
    > > Thanks,
    > >
    > > --
    > > bic

    >
    >
    >
     
    =?Utf-8?B?Ymlj?=, Oct 4, 2007
    #3
  4. =?Utf-8?B?Ymlj?=

    sloan Guest

    dim x as string = Convert.ToString ( a.UpdateAdStatus () )

    lblMessage.Text = x

    ........

    You do explicit converts/casts in order to avoid confusion.


    Old VB6 code

    dim s as string
    s = 6 + 2

    do you want 8 or "62"

    ...

    In DotNet, you say what you want

    dim s as string

    s = Convert.ToString(6) + Convert.ToString(2)
    's would be 62

    s = Convert.ToString ( 6+2 )
    's would be 8

    .............

    "bic" <> wrote in message
    news:...
    > when I do this in my page
    > lblMessage.Text = a.UpdateAdStatus( ....);
    > it causes an cannot implicitly convert type 'int' to 'string' error, for
    > the method has a return type of int. Are you suggesting that I simply
    > just do
    > a.UpdateAdStatus( ....);
    > instead?
    >
    > Thanks,
    > --
    > bic
    >
    >
    > "sloan" wrote:
    >
    >>
    >> I'd read this:
    >>
    >> http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx
    >>
    >> since you have a "throw", the exception gets bubbled up.
    >>
    >> the "page" you have would probably catch the exception, and then display
    >> a
    >> message to the user.
    >>
    >> in winforms, if you don't handle the exception in the "page", your app
    >> will
    >> crash.
    >>
    >> in webforms, if you don't handle the exception in the "page", your page
    >> will
    >> show a nasty dotnet type exception message.
    >>
    >>
    >> "bic" <> wrote in message
    >> news:...
    >> > Hi,
    >> >
    >> > Calling my method below how does my page caller display the exception
    >> > since
    >> > the return type is int?
    >> >
    >> > int ret = 0;
    >> > string spname = "sp_UpdateAd";
    >> > try
    >> > {
    >> > //Retrieve the parameters from the cache
    >> > SqlParameter[] storedParams =
    >> > SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
    >> > if( storedParams == null )
    >> > {
    >> > //Cache the parameters
    >> > SqlParameter[] paramsToStore = new SqlParameter[]
    >> > {
    >> >
    >> > };
    >> > SqlHelperParameterCache.CacheParameterSet( connString, spname,
    >> > paramsToStore );
    >> > storedParams = paramsToStore;
    >> > }
    >> > ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
    >> > spname, storedParams );
    >> > }
    >> > catch( Exception ex ) { throw; }
    >> > finally{} // Do NOT dispose connection
    >> >
    >> > return ret;
    >> >
    >> > Thanks,
    >> >
    >> > --
    >> > bic

    >>
    >>
    >>
     
    sloan, Oct 8, 2007
    #4
    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. Rajesh Madhra

    SQLHelper Class problem

    Rajesh Madhra, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    469
    Rajesh Madhra
    Jul 16, 2003
  2. Rajesh Kumar
    Replies:
    1
    Views:
    2,151
    samir1_84
    Nov 14, 2009
  3. Rajesh Madhra
    Replies:
    0
    Views:
    535
    Rajesh Madhra
    Jul 18, 2003
  4. Mike Fors

    SqlHelper problem

    Mike Fors, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Mike Fors
    Aug 22, 2003
  5. John Dow
    Replies:
    0
    Views:
    861
    John Dow
    Feb 10, 2009
Loading...

Share This Page