Wednesday, 28 August 2013

C# Compare a string to a SqlExtension

C# Compare a string to a SqlExtension

I am currently working with SQL on my C# asp.net page. I insert a value
into the DataBase, but then if the ID is duplicate i get this exception:
{"Violation of PRIMARY KEY constraint 'PK_Section'. Cannot insert
duplicate key in object 'dbo.Section'.\r\nThe statement has been
terminated."}
What i want to do is to treat the exception doing something like:
if(exception=={"Violation of PRIMARY KEY constraint 'PK_Section'. Cannot
insert duplicate key in object 'dbo.Section'.\r\nThe statement has been
terminated."})
//update values instead of insert
My problem is that i cant compare exception(wich is a string) with that
long "string" that i get from trying to duplicate the IDs.
Is there anyway that i can compare this so that i can properly work on a
solution to this error?

No comments:

Post a Comment