This is an example of a well-worded post which provides almost all
information required for a helpful answer (with the notable exception
of framework version) and shows that the poster has invested some
effort in solving the problem. The code presented is a relevant
snippet and a reader does not need to carefully read pages upon pages
of long uncommented code to comprehend the flow. We need more posters
who put some effort into the formulation of their questions !!

Laura,

You don't appear to be setting the ClassID column value anywhere in
the code. I think it would come from the Selectedvalue of the
DropDownList and when you update the DataAdapter, and changes should
then be propagated to the Students table in the database.

On Jan 9, 5:10 pm, Laura <[email protected]> wrote:
> 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