How would I know if a particular data is present in database or not? For E.g. If the Database already has “Student_Id” and “Course_Id” in a table then update the record else insert the record.
I already have a controller action which I use to insert the data, but I want to add an additional feature where it checks the database (SQL Server) and does insert/update based on whether the record is present or now.
I use Linq to SQL to insert data.
Thanks in advance
You could check if the data is there via a simple select statement, prior to adding the data.
Ideally though, you should design the database to make
Student_IdandCourse_Ida combined unique key for this table, so your code won’t be able to add them at all if a record is already there.As Maess asked, how are the values being generated? Your options could change depending on whether the data is user-generated or not. For example; if you have two dropdown boxes to select a student and a course, don’t allow the user to select a course that the student is already diong.