I have a winforms app which inserts records into a table and should return the ID. It was working but for some reason has stopped.
I have changed my code so many times now in an attempt to fix this but I cannot get it to workl correctly.
It keeps returning the value of 1 which , I presume is the number of rows affected as opposed to the ID of the row affected.
SQL INsert statement
INSERT INTO [FacilityHistory] ([Memberno], [RegNo], [Sport], [Nature], [Class], [Type], [DateofEvent], [Duration], [Starttime], [ReportTime], [ReportPlace], [LeavewithPay], [LeaveOwnTime], [Remarks], [M1], [R1], [M2], [R2], [M3], [R3], [M4], [R4], [M5], [R5], [M6], [R6], [M7], [R7], [M8], [R8], [M9], [R9], [M10], [R10], [M11], [R11], [M12], [R12], [M13], [R13], [OM1], [OR1], [OM2], [OR2]) VALUES (@Memberno, @RegNo, @Sport, @Nature, @Class, @Type, @DateofEvent, @Duration, @Starttime, @ReportTime, @ReportPlace, @LeavewithPay, @LeaveOwnTime, @Remarks, @M1, @R1, @M2, @R2, @M3, @R3, @M4, @R4, @M5, @R5, @M6, @R6, @M7, @R7, @M8, @R8, @M9, @R9, @M10, @R10, @M11, @R11, @M12, @R12, @M13, @R13, @OM1, @OR1, @OM2, @OR2);
SELECT FacID FROM [FacilityHistory] WHERE (FacID= SCOPE_IDENTITY())
code behind statement
NewID = FacilityHistoryTableAdapter.InsertQuery1(MemNo, strRegNo1, cboSpraSection.SelectedValue, TextBox6.Text, _
f1, cboType.SelectedIndex, dtp1.Value, nud1.Value, ST, _
RT, TextBox1.Text, nud2.Value, nud3.Value, TextBox2.Text, _
M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, _
R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, OM1, OM2, OR1, OR2)