Partial Class Dcops_Maint
Inherits System.Web.UI.Page
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, _
ByVal e As DetailsViewInsertedEventArgs) _
Handles DetailsView1.ItemInserted
If e.AffectedRows = 0 Then
If (e.Exception.Message.IndexOf("Violation of PRIMARY KEY") >= 0) Then
'Duplicate key error is SqlException Number = 2601
lblDetailsViewMessage.Text = "Record Already Exists in the database"
Else
' "Error occurred when inserting:"
lblDetailsViewMessage.Text = e.Exception.Message.ToString()
End If
lblDetailsViewMessage.Style.Value = "font-weight: bold; font-size: 13px;" _
& "color: red; font-style: italic; font-family: Cambria"
e.ExceptionHandled = True
e.KeepInInsertMode = True
Else
lblDetailsViewMessage.Text = ""
End If
End Sub
Protected Sub DetailsView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.Load
lblDetailsViewMessage.Text = ""
End Sub
|