You can do that in following ways
Check if duplicate
Create a method to check the username is already exists in database
public bool IsUsernameExists(string strUsername)
{
}
Or
Throw the exception
Put a constraint for the
UserName
column in table. If you try to save duplicate name then it will raise the error, based on the error you can throw the appropriate message to the user.
Now you decide.