SQL Query没有在VB 2013中填充组合框

时间:2015-03-10 19:32:17

标签: mysql sql vb.net combobox dataset

任何人都可以提供有关为什么第一个组合框被填充而第二个组合没有填充的见解吗?我在MySQL工作台中构建了第二个查询,它运行正常。但是我的应用程序不会将任何结果返回到组合框中。

        'populate my projects combo1
        Dim da1 As New MySqlDataAdapter("SELECT * FROM stylus_projects WHERE aid = '" & Me.aid.Text & "' ORDER by title asc", sql.SQLcon)
        Dim dt1 As New DataTable
        da1.Fill(dt1)
        ComboBox1.DisplayMember = "title"
        ComboBox1.ValueMember = "id"
        ComboBox1.DataSource = dt1

        'populate contrib combo2
        Dim da2 As New MySqlDataAdapter("SELECT DISTINCT stylus_contrib.pid,stylus_projects.title FROM stylus_contrib INNER JOIN stylus_projects ON stylus_contrib.pid = stylus_projects.id WHERE stylus.contrib.aid = 3", sql.SQLcon)
        Dim dt2 As New DataTable
        da2.Fill(dt2)
        ComboBox2.DisplayMember = "title"
        ComboBox2.ValueMember = "pid"
        ComboBox2.DataSource = dt2

2 个答案:

答案 0 :(得分:0)

将表名与字段名一起使用。 它应该像

ComboBox2.DisplayMember = "stylus_projects.title" ComboBox2.ValueMember = "stylus_contrib.pid"

答案 1 :(得分:0)

我明白了。在粗体区域中,我有一段时间而不是手写笔和contrib之间的下划线。 D'哦!

Dim da2 As New MySqlDataAdapter("SELECT DISTINCT stylus_contrib.pid, stylus_projects.title FROM stylus_contrib INNER JOIN stylus_projects ON stylus_contrib.pid = stylus_projects.id WHERE **stylus_contrib.aid** = '3'", sql.SQLcon)
        Dim dt2 As New DataTable
        da2.Fill(dt2)
        ComboBox2.DisplayMember = "title"
        ComboBox2.ValueMember = "pid"
        ComboBox2.DataSource = dt2