![]() |
Click here to advertise with us
|
|
|||||||
| Database General Discussion General discussion on database related topics |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
I am using VB.NET express and MS Access.1. I have a Table named EVENTthat contains: 1. RaceID (1..14) 2. RaceName (50 yard, 100 yard, etc) I populate my cboRace with the Raceame information. User can select the RaceName from the list and then submit it. OnSubmit, I am trying to update RaceID in another table named RESULT containing RaceID, EventID, etc I have tried setting Databinding on the cboRace and it still does not work. How can this be done? |
|
||||
|
In future, don't just say "I tried and it didn't work". Please show/tell us exactly what you did and exactly what happened.
You need to set the ValueMember of the ComboBox to the name of the column/property you want returned and then you get the value that corresponds to the selection from the SelectedValue property.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
|
|||
|
I apologize for being so vague:
Here is the code that calls the DB and populates the combo box. cmd = New OleDb.OleDbCommand("select * from Event", cn) ==> EVENT has RaceID and RaceType Try UnitIDReader = cmd.ExecuteReader If UnitIDReader.HasRows Then While UnitIDReader.Read() race.ValueMember = UnitIDReader("RaceType") race.Items.Add(UnitIDReader("RaceType").ToString) End While End If Catch End Try combobox is populated with Race information RaceType (String = 50 meter backstroke) I have attached a screenshot of the control 1. When I do the binding, the control comes up empty 2. When I do not do binding, I get the values, but Selected Value is always NULL. Thank you. Mate |
|
||||
|
combo.datasource = event
displaymember = racename valuemember = raceid selectedvalue databinding is bound to result.raceid remember: fill the event table remember: do not bind the combo's text property remember: there is NO NEED for a datarelation between result and event remember: youre NOT supposed to be using a data reader and then adding the items to the combo; youre supposed to be filling the event datatable and the result datatable! replace all this junk: Code:
cmd = New OleDb.OleDbCommand("select * from Event", cn) ==> EVENT has RaceID and RaceType
Try
UnitIDReader = cmd.ExecuteReader
If UnitIDReader.HasRows Then
While UnitIDReader.Read()
race.ValueMember = UnitIDReader("RaceType")
race.Items.Add(UnitIDReader("RaceType").ToString)
End While
End If
Catch
End Try
Code:
Me.EventTableAdapter.Fill(swimdataset1.Events)
__________________
DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|