473,834 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

continue execution after try/catch

I have a For loop to insert record to a SQL server database, like:
For Each item As ListItem In cblxyz.Items
If (item.Selected) Then
.... do something
Try
srcxyz.Insert()
Catch SQLExp As SqlException
....display error
End Try
End If
Next

Now when a duplicate record is encountered, it displays the error and then
stops. I need the loop to go on after displaying the database error. Is
there any way to do that? Or do I have to check whether the record is
already existing in the database every single time before doing the Insert?

Any insight appreciated.

I'm using VS2005, SQL Server 2000, .Net 2.0

Aug 23 '08 #1
3 2283
What do you mean by "it stops".

If the Catch doesn't do anything to cause execution to go anywhere
else, execution should resume after the End Try.

Set a breakpoint on the Catch and step it to see what happens.

On Fri, 22 Aug 2008 17:45:58 -0700, "E. Kwong"
<ekwong999AThot mail.comwrote:
>I have a For loop to insert record to a SQL server database, like:
For Each item As ListItem In cblxyz.Items
If (item.Selected) Then
... do something
Try
srcxyz.Insert()
Catch SQLExp As SqlException
....display error
End Try
End If
Next

Now when a duplicate record is encountered, it displays the error and then
stops. I need the loop to go on after displaying the database error. Is
there any way to do that? Or do I have to check whether the record is
already existing in the database every single time before doing the Insert?

Any insight appreciated.

I'm using VS2005, SQL Server 2000, .Net 2.0

Aug 23 '08 #2
"E. Kwong" <ekwong999AThot mail.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>I have a For loop to insert record to a SQL server database, like:
For Each item As ListItem In cblxyz.Items
If (item.Selected) Then
... do something
Try
srcxyz.Insert()
Catch SQLExp As SqlException
....display error
End Try
End If
Next

Now when a duplicate record is encountered, it displays the error and then
stops. I need the loop to go on after displaying the database error.
Is there any way to do that? Or do I have to check whether the record is
already existing in the database every single time before doing the
Insert?

Any insight appreciated.

I'm using VS2005, SQL Server 2000, .Net 2.0
How do you "display error"? In a message box, by any chance?

Aug 23 '08 #3
Thanks Jack Jackson and PvdG42.

It turns out that I did not get the correct checkboxlist value to create the
record.
"PvdG42" <pv**@toadstool .eduwrote in message
news:uB******** ******@TK2MSFTN GP05.phx.gbl...
"E. Kwong" <ekwong999AThot mail.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>I have a For loop to insert record to a SQL server database, like:
For Each item As ListItem In cblxyz.Items
If (item.Selected) Then
... do something
Try
srcxyz.Insert()
Catch SQLExp As SqlException
....display error
End Try
End If
Next

Now when a duplicate record is encountered, it displays the error and
then stops. I need the loop to go on after displaying the database
error. Is there any way to do that? Or do I have to check whether the
record is already existing in the database every single time before doing
the Insert?

Any insight appreciated.

I'm using VS2005, SQL Server 2000, .Net 2.0
How do you "display error"? In a message box, by any chance?

Aug 25 '08 #4

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

Similar topics

2
2699
by: Michael Satterwhite | last post by:
I *MUST* be overlooking something obvious. Consider the following code: foreach($_POST as $key=>$value) { print "$key=>$value<br />"; if(! empty($value)) { switch($key) { case "Submit": case "keyList": case "curKey": print "Matched exception<br />";
3
423
by: Antipode | last post by:
Hi, I'm writing a simple application that deletes multiple directories. I want to write it so that it will simply continue on through the list of directories if an exception is thrown (the directory is not there). Is there a way to do this? Am I approaching this all wrong?
6
5086
by: Bern | last post by:
lets say i have the code: while (some condition){ /* the "big" loop */ .... some code.... while (some condition){ ...code... if (!some condition){
1
4673
by: ori | last post by:
Hi, I'm facing a problem when trying to continue normal execution flow within a HttpHandler ProcessRequest method. In my application we currently have a custom HttpHandler registered which validates a user against some Authentication method and then allows him to continue his request if successfully authenticated or denies him access if not. We use a handler to do this authentication and we'd like to continue normal execution if...
4
14895
by: James Radke | last post by:
Hello, I am attempting to use the proper Try/Catch technique when accessing my Microsoft SQL server database and have a question... If I use something similar to the following: Try set up SQL connection open the SQL connection
15
9172
by: PagCal | last post by:
Is this language missing the functionality of a C/C++ 'continue' statement? For example: While NOT isEof() If condition ' a C or C++ continue would work here ' but we are forced to use a GoTo GoTo nxt End If
12
1377
by: William | last post by:
VB6 had the ability to pause your execution while debugging, messing with the code, and continue executing right from where you left off. Is DotNet ever going to have this capability? I really miss it.
5
3929
by: Matthew Hood | last post by:
I have a DLL I created to handle all unknown errors using the Application.ThreadException event. I'm asking the user if they want to terminate the program or continue. This is working like I want. The program exits when I tell it to terminate, and when I continue, the program keeps running but the routine that generated the error exited. I want to take this a step further though. Instead of the routine that generated the error...
1
2012
by: Elmo Watson | last post by:
in a Try/Catch block - once an error is thrown, is there any way to set it so that it will continue through the rest of the procedure? (in the catch block, I'm firing off an email with the error message)
0
9646
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10512
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9332
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7760
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6957
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4427
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 we have to send another system

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.