根据vb.net中的组合框选择自动填充文本框

时间:2017-03-20 10:46:23

标签: vb.net dropdown

我已经为MS Access完成了,但是我在Vb.net中有一个订单表格,所以当用户从下拉框中选择一个值时,我想要他们的地址,邮政编码,联系电话等。根据下拉框中的选择自动填写。任何帮助都感激不尽。 感谢

1 个答案:

答案 0 :(得分:0)

这是我的意思的一个例子:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

    If Not ComboBox1.Text.Trim() = "Select Supplier" Then

        Using con As New OleDbConnection

            Try

                con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; " & _
                     "Data Source = " & My.Settings.dbpath  'your database path here
                con.Open()

                Dim sqlquery_select_suppliers As String

                sqlquery_select_suppliers = "SELECT * FROM Suppliers WHERE SupplierID = '" & ComboBox1.Text.Trim() & "';"

                Dim ds_suppliers As New DataSet

                Dim da_suppliers As OleDb.OleDbDataAdapter

                da_suppliers = New OleDbDataAdapter(sqlquery_select_suppliers, con)

                da_suppliers.Fill(ds_suppliers, "Suppliers")

                con.Close()

                txt_supplier_name.Text = CStr(ds_suppliers.Tables("Suppliers").Rows(0).Item("SupplierID"))

                'Here you can populate as many textboxes as you like

            Catch Ex as Exeption

            'Exeption message here

            End Try

        End Using

    End If

End Sub