我查过.ValueMember,发现它只能接受我假设的整数。我的问题是,如果我的联盟专栏返回ABC,那会是组合框的显示名称和值吗?如果是这样的话,我们将不胜感激。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New MySqlConnection("Server=xxx.xxx.xxx.xxx.;Database=database;Uid=username;Pwd=password;")
Dim da As New MySqlDataAdapter("SELECT league FROM league_names ORDER BY league ASC", con)
Dim dt As New DataTable
da.Fill(dt)
'Display table data in combobox
ComboBox1.DisplayMember = "league"
ComboBox1.ValueMember = "league"
ComboBox1.DataSource = dt
End Sub
这是对我有效的更新代码。我只是将所有mysql数据添加到DataGridView中,然后使用for each循环来获取名称。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New MySqlConnection("Server=xxx.xxx.xxx.xxx.;Database=database;Uid=username;Pwd=password;")
Dim da As New MySqlDataAdapter("SELECT league FROM league_names ORDER BY league ASC", con)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
For Each row As DataGridViewRow In DataGridView1.Rows
If Not row.IsNewRow Then
ComboBox1.Items.Add(row.Cells(0).Value.ToString)
End If
Next
End Sub