Protected Sub registerStudButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles registerStudButton.Click
        If Page.IsValid Then
            Dim selectedProgram As String() = studProgramDropDownList.SelectedItem.Text.Split(New Char() {" "})
            Dim selectedIntake As String = intakeDropDownList.SelectedItem.Text
            Dim selectedSupervisor As String = supervisorDropDownList.SelectedItem.Text
            Dim contactNo As String

            If contactStudTextBox.Text <> "" Then
                contactNo = contactStudTextBox.Text.Trim
            Else
                contactNo = Nothing
            End If

            Using ts As TransactionScope = New TransactionScope()
                Dim newStudent As New student_Detail With _
                    {.student_ID = matrixNoTextBox.Text.Trim, _
                     .student_Name = nameStudTextBox.Text.Trim, _
                     .student_IC = ICStudTextBox.Text.Trim, _
                     .program_Code = selectedProgram(0), _
                     .student_Email = emailStudTextBox.Text.Trim, _
                     .student_Contact_No = contactNo, _
                     .photo = Nothing, _
                     .CGPA = Nothing, _
                     .user_ID = usernameStudTextBox.Text.Trim, _
                     .supervisor_ID = selectedSupervisor(0), _
                     .semester_No = selectedIntake(0) _
                    }

                Dim newLogin As New userlogin With _
                    {.user_ID = usernameStudTextBox.Text.Trim, _
                     .user_Passwrd = passwordStudTextBox.Text, _
                     .user_Type = "S" _
                    }

                aasDB.userlogins.InsertOnSubmit(newLogin)
                aasDB.student_Details.InsertOnSubmit(newStudent)
                aasDB.SubmitChanges()
                ts.Complete()

            End Using

I cannot get value for the supervisor_ID and semester_No. What's wrong with this code?

Dim selectedIntake As String = intakeDropDownList.SelectedItem.Text
Dim selectedSupervisor As String = supervisorDropDownList.SelectedItem.Text

.supervisor_ID = selectedSupervisor(0), _
.semester_No = selectedIntake(0) _


Thanks.

This is the error message.

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_student_Details_lecturer_Details". The conflict occurred in database "SKTM-AAS", table "dbo.lecturer_Details", column 'supervisor_ID'. The statement has been terminated.

This article has been dead for over six months. Start a new discussion instead.