I am working on a school activity. This is my sample form:
sample form http://i53.tinypic.com/14xlrl.png
What I’m trying to do is that when a user adds a record that has the same CourseID (Primary Key) with one of the records listed, there should be some Message box that will appear that says “Cannot insert same CourseID or cannot duplicate CourseID (Because PRIMARY KEY cannot be DUPLICATED).”
I believe you are manually inserting CourseID. A better way is to make the CourseID column auto-incrementing in SQL Server.
Secondly, if you seriously created a primary key, it won’t accept duplicates. You only need to catch the Exception. Check these links on Exception Handling:
Throwing Exceptions in C#
Exceptions and Exception Handling (C# Programming Guide)