Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string? GetDuplicateEntryErrorMessage(DbUpdateException ex)
- {
- var sqlException = ex.InnerException as SqlException;
- if (sqlException != null)
- {
- // Extract the duplicated values from the error message
- string errorMessage = sqlException.Message;
- int startIndex = errorMessage.IndexOf("(") + 1;
- int endIndex = errorMessage.IndexOf(")");
- string duplicateValues = errorMessage.Substring(startIndex, endIndex - startIndex);
- string errorDescription = endIndex > startIndex ? "Duplicate Values" : "Duplicate Value";
- return $"Duplicate Value: {duplicateValues}";
- }
- return null; // No duplicate entry error
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement