1

好吧,我又遇到了另一个问题,所以我有 2 个组合框,第一个称为 client_number,第二个是 order_number 好吧,当我在第一个组合中选择客户端时,我试图做下一个组合,第二个加载客户端完成的 order_number。MySql 查询是这样的:

SELECT 
order.number
FROM order,client 
WHERE order.client_number=client.number and client.number=" & ComboBox1.SelectedValue

当我运行程序时,第二个组合框会向我加载 order_number,但如果客户完成了多个订单,order_number 会出现,但order_number如果客户完成 2 个订单只出现一个,则只会出现一个。我能做什么?

顺便说一句,这就是代码

     Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
    conexao.Open()
    Dim strsql As String, i As Integer = 0
    Dim o As Integer
    o = ComboBox2.SelectedValue
    strsql = "SELECT count(order.number),order.number FROM order,client WHERE order.client_number=client.number and client.number=" & ComboBox3.SelectedValue
    sqlcom = New MySqlCommand(strsql, conexao)
    dr = sqlcom.ExecuteReader
    If Not dr.HasRows Then
        MsgBox("not find")
    Else
        dr.Read()
        ComboBox2.Items.Add(dr("order_number"))
        'TextBox10.Text = dr(0).ToString
    End If
    dr.Close()
    conexao.Close()

End Sub

我正在使用文本框来计算数字顺序,并且文本框可以正常工作,但组合不会加载多个订单

4

2 回答 2

1

您需要遍历阅读器中的行并添加如下项目:

If Not dr.HasRows Then
        MsgBox("not find")
    Else
        While dr.Read()
            ComboBox2.Items.Add(dr("n_enc"))
            TextBox10.Text = dr(0).ToString 'This probably should be elsewhere!
        End While
    End If

查看您的查询,我看不到“n_enc”被选中,但假设既然您说它确实填充了您的单个项目ComboBox,那么一切都很好。此外,您可能希望将此行移至其他位置:

TextBox10.Text = dr(0).ToString
于 2013-06-28T11:12:37.720 回答
0
SELECT 
order.number
FROM order
WHERE order.client_number=" & ComboBox1.SelectedValue

我想这会奏效

于 2013-06-28T10:45:00.850 回答