asp.net - C# Compare a string to a SqlExtension -
i working sql on c# asp.net page. insert value database, if id duplicate exception:
{"violation of primary key constraint 'pk_section'. cannot insert duplicate key in object 'dbo.section'.\r\nthe statement has been terminated."}
what want treat exception doing 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 cant compare exception(wich string) long "string" trying duplicate ids.
is there anyway can compare can work on solution error?
you should catch sqlexception
(which innerexception of exception) , check number
property identify exception.
see http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.number.aspx
Comments
Post a Comment