user2423011
user2423011

Reputation: 23

Combobox.Items.Add visual basic

Well i have another problem again,so i have 2 comboboxes the first one is called client_number and the second one is order_number well i was trying to do the next when i select a client in the first combo the second loads the order_number that client done. MySql query is this:

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

When i run the program, the second combobox loads me the order_number but if the client have done more than one order,the order_number appear but just appear one order_number if the client done 2 order just appear one.What i can do?

By the way thats the code

     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

I was using a textbox to count the number order and is working perfectly the textbox but the combo doesnt load more than one order

Upvotes: 1

Views: 2152

Answers (2)

Ric
Ric

Reputation: 13248

You need to loop through the rows in your reader and add the items like so:

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

Looking at your query, I cannot see "n_enc" being selected, but assume that since you say it does indeed populate a single item in your ComboBox, then all is ok. Also, you may want to move this line somewhere else:

TextBox10.Text = dr(0).ToString

Upvotes: 1

Thangamani  Palanisamy
Thangamani Palanisamy

Reputation: 5300

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

I guess this will work

Upvotes: 0

Related Questions