0
我的vb.net应用程序中有一个窗体,用于获取关于返回的库存的数据。该表单包含两个组合框。一个名为combobox5的包含发票号码,另一个名为combobox3包含派对代码。两个组合框都是使用sqldataadapter预加载的。如何通过循环浏览vb.net中的组合框项来选择组合框上的特定值
现在我想要的是在combobox5中更改发票号码时更改combobox3中的派对代码。进一步详细阐述,当股票发行时,派代码与发票号码一起存储以跟踪哪一方是股票发行。现在,当股票被退回时,我想跟踪哪一方已经退回股票,我希望当发票号码被更改时应该自动选择派代码,并且它应该是针对该特定发票号码存储在数据库中的内容。 ...
我用下面的代码这样做:
Private Sub ComboBox5_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox5.SelectedIndexChanged
' defines a new connection to the database
Dim con As New SqlConnection("Data Source=TAHA;Initial Catalog=ADT;Integrated Security=True")
con.Open()
If ComboBox5.SelectedIndex = 0 Then
ComboBox3.Enabled = True
If Not ComboBox3.Items.Count = 0 Then
ComboBox3.SelectedIndex = 0
End If
Else
Me.ComboBox3.Enabled = False
Me.ComboBox3.BackColor = Color.White
Me.ComboBox3.ForeColor = Color.Black
Dim invoices As New SqlCommand("select invoice_no, party_code from Outgoing_Invoice group by invoice_no, party_code", con)
Dim reader As SqlDataReader = invoices.ExecuteReader
While reader.Read
Dim cnt, i As Integer
cnt = Me.ComboBox3.Items.Count
If Me.ComboBox5.SelectedItem.ToString.Trim = reader("invoice_no").ToString.Trim Then
If Not cnt = 0 Then
For i = 0 To cnt - 1
If Me.ComboBox3.Items.Item(i).ToString.Trim.Contains(reader("party_code").ToString.Trim) Then 'here i have also used equals instead of contains but that too doesn't work
Me.ComboBox3.SelectedIndex = i
Exit For
End If
Next
End If
End If
End While
reader.Close()
End If
con.Close()
End Sub