Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Catch... try block

Reply
Thread Tools

Catch... try block

 
 
JJ297
Guest
Posts: n/a
 
      10-31-2007
If I enter a new topic I don't get your topic was submitted...

If I enter in a duplicate I do get teh duplicate error message. What
am I doing wrong?


Catch ex As Data.SqlClient.SqlException
'Throw New ApplicationException("An error occurred while
trying to insert the record")
If TopicTxt.Text = "" Then
Lbloutcome.Text = "Your topic was submitted into the
database."
Else
Lbloutcome1.Text = "Duplicate entry topic already in
database, topic was not submitted"
End If

 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      10-31-2007
The code inside
Catch ex As Data.SqlClient.SqlException

is only going to run .. is something blows up.

.........

I would go through this blog:
http://blogs.msdn.com/kcwalina/archi...16/396787.aspx

and rework the code.




"JJ297" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> If I enter a new topic I don't get your topic was submitted...
>
> If I enter in a duplicate I do get teh duplicate error message. What
> am I doing wrong?
>
>
> Catch ex As Data.SqlClient.SqlException
> 'Throw New ApplicationException("An error occurred while
> trying to insert the record")
> If TopicTxt.Text = "" Then
> Lbloutcome.Text = "Your topic was submitted into the
> database."
> Else
> Lbloutcome1.Text = "Duplicate entry topic already in
> database, topic was not submitted"
> End If
>



 
Reply With Quote
 
 
 
 
jx.su.go@gmail.com
Guest
Posts: n/a
 
      10-31-2007
On Oct 31, 11:49 pm, "sloan" <(E-Mail Removed)> wrote:
> The code inside
> Catch ex As Data.SqlClient.SqlException
>
> is only going to run .. is something blows up.
>
> ........
>
> I would go through this blog:http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
>
> and rework the code.
>
> "JJ297" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
>
>
> > If I enter a new topic I don't get your topic was submitted...

>
> > If I enter in a duplicate I do get teh duplicate error message. What
> > am I doing wrong?

>
> > Catch ex As Data.SqlClient.SqlException
> > 'Throw New ApplicationException("An error occurred while
> > trying to insert the record")
> > If TopicTxt.Text = "" Then
> > Lbloutcome.Text = "Your topic was submitted into the
> > database."
> > Else
> > Lbloutcome1.Text = "Duplicate entry topic already in
> > database, topic was not submitted"
> > End If- Hide quoted text -

>
> - Show quoted text -



the catch will harm the performance.
judge the text of Lbloutcome before insert this data to database.

 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      10-31-2007
First, I would design it so you do not have to "blow up" with a duplicate
insert. I would, instead, use ExecuteNonQuery on a stored procedure and
return 0 if there is already a record. In this way, you can return an
"error" message without actually throwing an exception (which is expensive).

As for why you are not getting the success message, the answer is simple:
You are succeeding. Catch only works when you have an error. Since the data
entered the database without problem, there was no error, and there is no
message.

I would redesign for success (the rule) rather than failure (the exception).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"JJ297" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> If I enter a new topic I don't get your topic was submitted...
>
> If I enter in a duplicate I do get teh duplicate error message. What
> am I doing wrong?
>
>
> Catch ex As Data.SqlClient.SqlException
> 'Throw New ApplicationException("An error occurred while
> trying to insert the record")
> If TopicTxt.Text = "" Then
> Lbloutcome.Text = "Your topic was submitted into the
> database."
> Else
> Lbloutcome1.Text = "Duplicate entry topic already in
> database, topic was not submitted"
> End If
>



 
Reply With Quote
 
JJ297
Guest
Posts: n/a
 
      10-31-2007
On Oct 31, 12:58 pm, "Cowboy \(Gregory A. Beamer\)"
<(E-Mail Removed)> wrote:
> First, I would design it so you do not have to "blow up" with a duplicate
> insert. I would, instead, use ExecuteNonQuery on a stored procedure and
> return 0 if there is already a record. In this way, you can return an
> "error" message without actually throwing an exception (which is expensive).
>
> As for why you are not getting the success message, the answer is simple:
> You are succeeding. Catch only works when you have an error. Since the data
> entered the database without problem, there was no error, and there is no
> message.
>
> I would redesign for success (the rule) rather than failure (the exception).
>
> --
> Gregory A. Beamer
> MVP, MCP: +I, SE, SD, DBA
>
> *************************************************
> | Think outside the box!
> |
> *************************************************" JJ297" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
>
>
> > If I enter a new topic I don't get your topic was submitted...

>
> > If I enter in a duplicate I do get teh duplicate error message. What
> > am I doing wrong?

>
> > Catch ex As Data.SqlClient.SqlException
> > 'Throw New ApplicationException("An error occurred while
> > trying to insert the record")
> > If TopicTxt.Text = "" Then
> > Lbloutcome.Text = "Your topic was submitted into the
> > database."
> > Else
> > Lbloutcome1.Text = "Duplicate entry topic already in
> > database, topic was not submitted"
> > End If- Hide quoted text -

>
> - Show quoted text -


Okay thanks!

 
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
Fo:Block can you check to see if a block contains any text by using the block id? morrell XML 1 10-10-2006 07:18 PM
Can I have a second TRY inside the first TRY/CATCH in ASP.NET ??? bienwell ASP .Net 4 05-27-2005 05:05 PM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
Try, Try, Try, again... Rick12N4@netscape.net Computer Support 3 01-29-2005 04:02 PM



Advertisments