代码下拉列表显示mysql表中的值

时间:2014-02-02 11:26:22

标签: mysql vb.net combobox xampp

如何在vb2010中对组合框进行编码,以便从mysql中显示表中字段的值?我似乎无法在网上找到任何东西(可能是因为我不知道如何对搜索进行短语)。

连接字符串:("Server=localhost;database=ba-solutions;user id=root;password=")

   Private Sub cbxCompanyName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxCompanyName.SelectedIndexChanged
    Try
        'we open Connection
        connection.Open()

        With mycommand
            .CommandText = "SELECT `companyname` from client_details;"
        End With
        'declare dt as new datatable
        Dim dt As New DataTable

        With cbxCompanyName


            myadapter.SelectCommand = mycommand
            'it fills the da values into dt
            myadapter.Fill(dt)
            'dt provides the data surce of combobox
            .DataSource = dt
            'specify the what to display
            .DisplayMember = "companyname"
            'and the value
            .ValueMember = "companyname"
        End With
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    connection.Close()
End Sub

结束班

0 个答案:

没有答案