Jump to content

Coluna do datatable numa combobox


Baia
 Share

Recommended Posts

Algém me pode dizer como eu mostro uma coluna  do datatable numa combobox?

Ou seja... tenho um Datatable com varias colunas e queria colocar as linhas de uma coluna numa Combobox para selecção...  ? 😛

Link to comment
Share on other sites

Dim connString as String = "mete aqui o caminho da bd;"
Dim connection As New SqlConnection(connString)
Dim query As String = "SELECT * FROM Tabela"
Dim da As New SqlDataAdapter(query, connection)
Dim dt As New DataTable
dt.Fill(ds, "Tabela")
With ComboBox1
    .DataSource = dt
    .DisplayMember = "Tabela_nome"
    .ValueMember = "Tabela_id"
    .SelectedIndex = 0
End With

Creio que seja isto, experimenta.

Link to comment
Share on other sites

Dim connString as String = "mete aqui o caminho da bd;"
Dim connection As New SqlConnection(connString)
Dim query As String = "SELECT * FROM Tabela"
Dim da As New SqlDataAdapter(query, connection)
Dim dt As New DataTable
dt.Fill(ds, "Tabela")
With ComboBox1
    .DataSource = dt
    .DisplayMember = "Tabela_nome"
    .ValueMember = "Tabela_id"
    .SelectedIndex = 0
End With

Creio que seja isto, experimenta.

Só uma correcção:

da.Fill(dt)

ao invés de...

dt.Fill(ds, "Tabela")
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.