473,795 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executenonquery method

Hi,

I'm trying to insert a number of records in a SQL server
table using the executenonquery method. This works fine
except when the records already exist which results in a
runtime error.

Is there a way to prevent this runtime error and just
ignore that the records can't be added ?

Thanks,

Marcel
Nov 18 '05 #1
2 1736
hi marcel,
1) you can trap the exception that your SQL data provider
throws, and force the application to ignore the error -
and even rerun the query after discarding the duplicate
rows if necessary
2) there may be a way to use the SQL data objects within
asp.net to tell it to ignore duplicates upon insert - I'm
not sure, but think its worth a little research.

alex
-----Original Message-----
Hi,

I'm trying to insert a number of records in a SQL server
table using the executenonquery method. This works fine
except when the records already exist which results in a
runtime error.

Is there a way to prevent this runtime error and just
ignore that the records can't be added ?

Thanks,

Marcel
.

Nov 18 '05 #2
Marcel,

Your query probably stops running when it hits the first error... so even if
you trapped and the disregarded the error on your code you wouldn't get
anything after what caused the error to insert.

You could try to write a sproc that executes inserts one a time and traps
the error and resumes internally. I assume when you said you are inserting
a number of records that you are doing a batch update. You could also try
to insert these one at a time from your app instead of in chunks.

Regards,
Jason S.

"Marcel" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. .
Hi,

I'm trying to insert a number of records in a SQL server
table using the executenonquery method. This works fine
except when the records already exist which results in a
runtime error.

Is there a way to prevent this runtime error and just
ignore that the records can't be added ?

Thanks,

Marcel

Nov 18 '05 #3

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

Similar topics

1
25270
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In the code sample below, it bombs on the line with three *** when using the ExecuteReader, but works just fine when you use the ExecuteNonQuery. When using the ExecuteReader, the Output parameter appears to return a value of Null. The stored...
10
3401
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void AddMinimunWageStipen(string payrollid,double amount) { System.Data.SqlClient.SqlConnection cn = null; System.Data.SqlClient.SqlCommand cm = null;
5
10969
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper (Data Application Blocks for SQLServer), and calling the ExecuteNonQuery method in the SQLHelper class...
0
3078
by: johnnymack0730 | last post by:
Hello - I am currently working on an asp.net application that needs to be able to update an access table using ExecuteNonQuery method. I have all the code setup, it runs, there are no errors thrown, yet...nothing is being updated. The only thing I can see is the ExecuteNonQuery returns 0 when the update is run. Can anyone help please? Here is some of the code:
2
1528
by: jdb | last post by:
Hi, I am adding a record to the database using an ExecuteNonQuery, which adds without problem. Now after the record is added I run a method passing in some info as well as the curretnly opened connection (byRef cn as OleDbConnection). Am using an Access 2000 database. Now in this new method I create a command object using the passed in connection object. I then create a DataReader to read the database that has the record added in the...
2
2185
by: JIM.H. | last post by:
Hello, Is there any way I can run ExecuteNonQuery asynchronously, such as initiate stored procedure call and return immediately. Thanks,
2
1552
by: Fred Chateau | last post by:
This is a two part question. (1) After opening a connection and calling ExecuteNonQuery within a transaction in .NET 2.0, is any resource cleanup still required in a finally block? (2) My code calls the OpenRowset Bulk provider using a command query string, but it seemed ExecuteNonQuery was the proper method to call because nothing is returned. Is this correct?
8
4587
by: Tony M | last post by:
Shouldn't the ExecuteNonQuery be TRUE if it finds a record and FALSE is not? I get FALSE all the time and I seeded the database with the email address. I just want to check if record exist before moving on. If this doesn't work I guess I could load a datatable and check to see if rows 0. Dim cnString As OleDbConnection cnString = New OleDbConnection("Provider=MicroSoft.Jet.OLEDB.4.0; Data
1
6375
by: David | last post by:
Hello there, I am having problems with a stored procedure. When a use SqlCommand, SqlParameter and the ExecuteNonQuery method, i get this error: Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'spSaveFormRequest'. (1 row(s) affected)
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
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
6780
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
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.