Thanks,

The DisplayMember and ValueMember properties were just what I needed.

On Jan 13, 7:25 pm, Cerebrus <[email protected]> wrote:
> I'm not sure how you load items into your ComboBox... Do you add them
> manually or do you bind it to a Datasource ? I'm guessing it would be
> the latter, so my suggestion would be to use the DisplayMember and
> ValueMember properties to set it the way you want. Look them up or
> revert back if you have a question. ;-)
>
> On Jan 13, 8:48 pm, Laura <[email protected]> wrote:
>
>
>
> > Cerebrus,
>
> > Thanks for your compliments on my posting and also for your help.
>
> > I've managed to get the FName and SName saved alongside a ClassID but
> > to get it working I had to change the contents of the combo box
> > (cboClass) from "ClassName" to "ClassID". But this is not what I need
> > - for the user looking at the form he/she wants to see the class name
> > in the combo box. It'll make no sense to them reading an ID number.
> > When I leave ClassName as the contents of the combobox and run it, I
> > get an error: "Cannot set Column "ClassID" to be null. Please use
> > DBNull instead"
>
> >         objCurrentRow.Item("ClassID") = cboClass.SelectedValue
> >         objCurrentRow.Item("FName") = txtFName.Text
> >         objCurrentRow.Item("SName") = txtSName.Text
> >         objDataSet.Tables("tblStudent").Rows.Add(objCurrentRow)
> >         objStudentDA.Update(objDataSet, "tblStudent")
> >         objDataSet.AcceptChanges()
>
> > On Jan 9, 6:56 pm, Cerebrus <[email protected]> wrote:
>
> > > 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- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to