Try by adding a unique constraint on the column consumr_cn.
http://msdn.microsoft.com/en-us/library/ms177420(v=sql.105).aspx[
^]
Then try to catch this catch exception in your C# code behind.
Try
Catch ex As SqlException
If ex.Message.Contains("UniqueConstraint") Then
' do something
End If
End Try
It is maybe not the most elegant solution but it works.
Cheers
EDIT:
SqlException has a collection of SqlError objects: Errors. The SqlError have properties for error Number and you can compare this with the known constraint violation error numbers (eg. 2627).
While is true that SqlException itself exposes a Number property, it is not accurate if multiple errors happen in a single batch and hence is better to inspect the Errors collection.