Hi,

I have a database with multiple tables. Two tables are called
"Student" and "Class", these tables are related by the field
"ClassID".

I have a form that allows the user to create new student details and
save them.

On the form, you first select a class from a drop down list (eg. Class
A), then you enter the new student's first name and surname. That
student needs to be saved as a member of that class.

I have the code to save the details to the database, but it is simply
writing the names to the 'Student' table and not associating the new
student with a 'ClassID'.

What do I need to do to get the details to save alongside the ClassID?

Thanks in advance

(this is some of my existing code)
Private Sub btnSaveNewStudent_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSaveNewStudent.Click
        'save new student to database
        'relationship
        objDataSet.Relations.Clear()
        objDataSet.Relations.Add("Class2Student", _
                                 objDataSet.Tables("tblClass").Columns
("ClassID"), _
                                 objDataSet.Tables
("tblStudent").Columns("ClassID"))
        'Select the next new row
        objCurrentRow = objDataSet.Tables("tblStudent").NewRow
        mintStudentID = objDataSet.Tables("tblStudent").Rows.Count


        objCurrentRow.Item("FName") = txtFName.Text
        objCurrentRow.Item("SName") = txtSName.Text
        objDataSet.Tables("tblStudent").Rows.Add(objCurrentRow)
        objStudentDA.Update(objDataSet, "tblStudent")
        objDataSet.AcceptChanges()

        MsgBox("The new student record has successfully been added to
the system.", MsgBoxStyle.OkOnly, "Saved")

        txtFName.Text = ""
        txtSName.Text = ""

    End Sub

Reply via email to