Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Catch... try block

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JJ297 - 31 Oct 2007 15:44 GMT
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
sloan - 31 Oct 2007 16:49 GMT
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/archive/2005/03/16/396787.aspx

and rework the code.

> If I enter a new topic I don't get your topic was submitted...
>
[quoted text clipped - 11 lines]
> database, topic was not submitted"
>            End If
jx.su.go@gmail.com - 31 Oct 2007 17:47 GMT
> The code inside
>  Catch ex As Data.SqlClient.SqlException
[quoted text clipped - 24 lines]
>
> - Show quoted text -

the catch will harm the performance.
judge the text of Lbloutcome before insert this data to database.
Cowboy (Gregory A. Beamer) - 31 Oct 2007 17:58 GMT
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).

Signature

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

*************************************************

| Think outside the box!

*************************************************
> If I enter a new topic I don't get your topic was submitted...
>
[quoted text clipped - 11 lines]
> database, topic was not submitted"
>            End If
JJ297 - 31 Oct 2007 19:34 GMT
On Oct 31, 12:58 pm, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamM> 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
[quoted text clipped - 32 lines]
>
> - Show quoted text -

Okay thanks!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.