I am using datasets/dataadapters to connect to an Access database. I am populating the Drop down list with the below code:
Pubic Sub PopulateDropDown()
Dim i As Integer, strMovieName As String
For i = 1 To objDS.Tables("Movies").Rows.Count
strMovieName = objDS.Tables("Movies").Rows(i - 1).Item("MovieName")
cboMovie.Items.Add(strMovieName)
Next
End Sub
This seems to work fine. The dropdown populates with the data in column 'MovieName' of 'Movie' table.
I have the following code behind a button to save Actor data to a second table:
Dim objRow As DataRow
objRow = objDS.Tables("Actor").NewRow
objRow.Item("Actor") = txtActor.Text
objRow.Item("MovieName") = cboMovie.SelectedItem.Text
'cboMovie is the dropdownlist
I was hoping that whichever movie name I selected in the in the dropdown would be saved to the 'MovieName' column in the 'Actor' table. However, the same value always gets saved (i.e: the first in the list). Any idea how I can get the selected value to save to the 'Actor' table or how I could set a variable equal to the selected value in the drop down.
I am doing it this way so that it is only possible to add actor information to a Movie which already exists in the database.