I created a simple asp.net form which allow users to view a list of dates for a training and register for that date , they enter their name and employeeid manually ( i dont want to allow dulpicate employe ids), each date corresponds to a training ( unique id in table) this gets inserted in a table with the following structure:
tbl_emptraining
trainig_id ( which is unique)
trainingDate
employeename ( which is unique)
employeeID (entered ) needs to be unique on each trainig_id and unique for all different training ids..
How would I prevent that a employee register for duplicate trainig ids in the Sql Database. I want to fire an event where the message can be successfully displayed to the user that the employee has been register for a training ..???
Firstly, you should make sure the database has the correct constraints. In this case, a unique index on the employeeID field and a unique constraint on employeeName would probably be correct.
Then, in your business logic (the .net code, but it’s useful to have a defined layer for this) you would make a check to the database to see if the employeeName exists already. Then return a message if the name already exists.
Finally, you could use some javascript to make an realtime call to the database in the same way as above, but this would be optional.
Also, looking at what you’ve written, it seems your database schema might be better with a many to one relationship between training and employees.