簡體   English   中英

嘗試使用外鍵從組合框中獲取數據並更新數據庫

[英]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的數據庫表,其中包含ThingIdName列。 您通常會查詢數據庫以填充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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM