Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > Database General Discussion

Database General Discussion General discussion on database related topics

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2009, 8:32 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Mar 2005
Age: 39
Posts: 19
Reputation: 63
motti100 is on a distinguished programming path ahead
Default Cannot get ID from Combobox Value to Insert into Db

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-19-2009, 3:51 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,006
Reputation: 538
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-19-2009, 11:14 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Mar 2005
Age: 39
Posts: 19
Reputation: 63
motti100 is on a distinguished programming path ahead
Default Cannot get ID from Combobox Value to Insert into Db

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
Attached Images
File Type: jpg attachment.JPG (114.7 KB, 8 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-19-2009, 11:15 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,378
Reputation: 746
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

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
With:
Code:
Me.EventTableAdapter.Fill(swimdataset1.Events)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 11:27 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.