473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I catch duplicate record exception?

Hello All,

How do I catch duplicate record attempted to be added exception? As in:

Catch ex As Exception
Thanks,

Hexman


Aug 19 '06 #1
3 9131
Catch ex As Exception
If InStr(1, ex.ToString, "duplicate key") 0 Then

lblMessage.Text = " User already exists cannot insert
duplicate value."

Else

lblMessage.Text = ex.ToString()

End If

Finally
'close the connection here, the Finally part will always
execute
Conn.Close()
Hexman wrote:
Hello All,

How do I catch duplicate record attempted to be added exception? As in:

Catch ex As Exception
Thanks,

Hexman
Aug 20 '06 #2
Thanks Scorpion,

I just thought there would be a error number that could be tested for this condition, like H_Result.

Hexman

On 20 Aug 2006 05:14:35 -0700, "scorpion53061" <ad***@kjmsolutions.comwrote:
>Catch ex As Exception
If InStr(1, ex.ToString, "duplicate key") 0 Then

lblMessage.Text = " User already exists cannot insert
duplicate value."

Else

lblMessage.Text = ex.ToString()

End If

Finally
'close the connection here, the Finally part will always
execute
Conn.Close()
Hexman wrote:
>Hello All,

How do I catch duplicate record attempted to be added exception? As in:

Catch ex As Exception
Thanks,

Hexman
Aug 20 '06 #3
Hexman wrote:
How do I catch duplicate record attempted to be added exception? As in:

Catch ex As Exception
Start with this, generate the Exception and see what you get.

? ex.GetType().ToString()

Assuming this isn't just System.Exception, then change the Catch to
catch the required Type and examine each property of that subclass,
something like

Catch ex As ODBCException

? ex.Errors.Count
? ex.InnerException.ToString()

and so on. If you're lucky, you'll find something that identifies a
duplicate record exception explicitly. If not, you'll have to fall back
on looking for some text in the Message. This will work but isn't
ideal; the message generated could change with, say, an upgrade to the
DBMS software, thereby breaking your program.

HTH,
Phill W.
Aug 22 '06 #4

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

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
4
by: ad | last post by:
The code below can only catch common excption. I want to catch duplicate primary key exeption and do something more. How can I catch duplicate primary key exeption try { Insert a record to...
1
by: 2D Rick | last post by:
Access2003 in XP If I open a form to a specific record and click on a command button with the following code I get a duplcate record: DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
0
by: vbDavidC | last post by:
I am adding a new record to an Access table. This is a sample table with only 1 field which is a primary key. I can add the record ok if it is not a dup (or null). I am trying to learn the...
3
by: milecimm | last post by:
Hi, I want to check in the below code if the email exists in the database before inserting. How can I do that? Dim EmailAlertDataSource As New SqlDataSource() ...
6
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger",...
1
by: mlb992000 | last post by:
I have a form that has a duplicate record command button that allows the user to duplicate all information on the form and change two fields. I need to create an event that will clear the two fields...
2
by: Ranma13 | last post by:
Hello, I have a duplicate record check written in VB for a check in/check out database. Here's the pseudocode, written for the BeforeUpdate property on the form: If DCount(search for records with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...

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.