473,499 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Catch... try block

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

Oct 31 '07 #1
3 1284
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" <nc***@yahoo.comwrote in message
news:11**********************@50g2000hsm.googlegro 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

Oct 31 '07 #2
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" <nc***@yahoo.comwrote in message
news:11**********************@50g2000hsm.googlegro 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

Oct 31 '07 #3
On Oct 31, 12:58 pm, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamMwrote:
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" <nc...@yahoo.comwrote in message

news:11**********************@50g2000hsm.googlegro 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!

Oct 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2718
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
11
3454
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
3038
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
20
1335
by: Woody Splawn | last post by:
In a message yesterday titled Try Catch Question I got numerous responses. Thank you to all. After all the smoke clears I guess the question is where to place the Return True statement in the...
5
3012
by: PasalicZaharije | last post by:
Hallo, few days ago I see ctor like this: Ctor() try : v1(0) { // some code } catch(...) { // some code }
6
7427
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.