I am trying to check whether a username exists in my database before inserting the new row & display a message to the user if it does.
On my SqlDataSource my InsertCommand looks like this:
InsertCommand="IF NOT EXISTS (SELECT * FROM Users WHERE UserName = @UserName) BEGIN INSERT [Users] ([UserName], [FirstName], [LastName], [City], [State], [Country], [CompanyName], [Active], [PasswordHash]) VALUES (@UserName, @FirstName, @LastName, @City, @State, @Country, @CompanyName, @Active, @PasswordHash) END"
This works as expected: If the username is unique, the row is created.
If the username already exists, the row is not added.
The problem is, if the row already exists, the insert is rejected but the user is not notified.
So my question is, is there a way I can notify the user?
Maybe something like: InsertCommand = "If Not Exists (select....) Begin Insert... Else Notify User Somehow End
This is a basic database, I'm not using the built-in membership provider nor will be.
View Complete Post