From the error, I guess that
SectionId
is the
PrimaryKey
of Table
Section_details
.
Your Update statement is correct as you are updating a particular Section after getting it (if it exists).
If it doesn't exist, you need to insert all the details, but you can't insert value to the
SecionId
as it is the
PrimaryKey
. That's why it is throwing exception that there is already a Section with Id
51.
insert into schoolcampus.dbo.Section_details(SectionId,SectionName,className,AcademicYear,Createddatetime,adminid,Medium) values(@sectionid,@sectionname,@classname,@acyear,@datetime,@adminid,@medium)
So, remove the
SectionId
insertion from this query. And after that it should run without any errors.
insert into schoolcampus.dbo.Section_details(SectionName,className,AcademicYear,Createddatetime,adminid,Medium) values(@sectionname,@classname,@acyear,@datetime,@adminid,@medium)