[英]Trying to take data from a combo box with a foreign key and update the database
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更新回我的数据库。 如果您需要更多信息,请告诉我。 主表是 TGolfers,父表是 TGenders。
我想我理解这个问题。 假设您有一个名为Thing
的数据库表,其中包含ThingId
和Name
列。 您通常会查询数据库以填充DataTable
,然后将其绑定到您的ComboBox
,例如
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
用户现在将在ComboBox
中看到Name
值列表,当它们为 select 时,您可以从SelectedValue
属性中获取相应的ThingId
,例如
Dim thingId = CInt(thingComboBox.SelectedValue)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.