I am trying to update my SQL database with the code provided, I am basically trying to take a select statement to bring back just the INTGenderID based on a combo box and make it equal to a string then convert that to an integer when I do my update back into my database. If you need more info let me know. The main table is TGolfers and the parent table is TGenders.
I think I understand the question. Let's assume that you have a database table named Thing
and that has columns ThingId
and Name
. You would generally query the database to populate a DataTable
and then bind that to your ComboBox
, eg
Dim table As New DataTable
Using connection As New OleDbConnection(connectionString),
command As New OleDbCommand("SELECT ThingId, Name FROM Thing", connection)
connection.Open()
Using reader = command.ExecuteReader()
table.Load(reader)
End Using
End Using
With thingComboBox
.DisplayMember = "Name"
.ValueMember = "ThingId"
.DataSource = table
End With
The user will now see a list of Name
values in the ComboBox
and, when they select one, you can get the corresponding ThingId
from the SelectedValue
property, eg
Dim thingId = CInt(thingComboBox.SelectedValue)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.