Dear readers,
How can I create friendly error messages in combination with a detailsview created in VS2005? I don't want to let the users put duplicate family details in my database. so I've created an index with Firstname, Lastname and Zip Code. Thats enough for the moment. When I now enter a family which is already in the database I get the message "Violation of UNIQUE KEY constraint 'IX_SEP_IN_TA_Famin'. Cannot insert duplicate key in object 'SEP_IN_TA_Famin'. The statement has been terminated"
How can I change this in a friendly message?
In asp.net 1.0 when I coded a form to insert, update and then I used the code:
Command1.Connection.Open()
Try
Command1.ExecuteNonQuery()
Label1.Text = "The family is created."
Catch Err As Exception
If err.Message.IndexOf("UNIQUE KEY") >= 0 Then
'Family already exist
Label1.Text = "The family already exists in the database, you can't add this family again."
End If
Finally
End Try
Command1.Connection.Close()
How can I implement this in a detailsview?
Kind regards,
Bart