Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > sqlHelper exception handling

Reply
Thread Tools

sqlHelper exception handling

 
 
=?Utf-8?B?Ymlj?=
Guest
Posts: n/a
 
      10-04-2007
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
 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      10-04-2007

I'd read this:

http://blogs.msdn.com/kcwalina/archi...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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?Ymlj?=
Guest
Posts: n/a
 
      10-04-2007
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/archi...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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      10-08-2007

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/archi...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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLHelper class problem : To Gregory A. Beamer Rajesh Kumar ASP .Net 1 11-14-2009 03:40 AM
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
SemaphoreFullException exception in SQLHelper class within a WCF service John Dow ASP .Net Web Services 0 02-10-2009 08:38 PM
SQLHelper Class problem : For Gregory A. Beamer Rajesh Madhra ASP .Net 0 07-18-2003 04:23 PM
SQLHelper Class problem Rajesh Madhra ASP .Net 0 07-16-2003 05:06 PM



Advertisments