Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  

Preencher Combo [Resolvido]

Recommended Posts


bem pessoal tenho aqui uma duvida.

Como é que preencho uma combobox com os valores de uma tabela de uma base de dados criada em mysql.


Share this post

Link to post
Share on other sites

eu tenho este codigo.

Dim mysql As String = "SELECT ModeloCodMar FROM tabmodelos"
        Dim connection As New MySqlConnection(myconnectionstring)
        Dim command As New MySqlCommand(mysql, connection)


        Dim reader As MySqlDataReader = command.ExecuteReader

        While reader.Read()
            ModeloCodMar = reader.GetString(0)
        End While

mas este codigo não dá. alguma sugestão?  😡

Share this post

Link to post
Share on other sites

ja consegui.

Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim myData As New DataTable
        Dim mySQL As String = "SELECT * FROM tabmarcas"
        Dim conn As MySqlConnection
        conn = New MySqlConnection
        conn.ConnectionString = (myconnectionstring)

                myCommand.Connection = conn
                myCommand.CommandText = mySQL
                myAdapter.SelectCommand = myCommand

                With cbModMarca
                    .DataSource = myData
                    .DisplayMember = "Marca"
                    .ValueMember = "Marca"
                    .SelectedIndex = 0
                End With

            Catch myerro As MySqlException
                MsgBox("Erro de leitura na Base de dados : " & myerro.Message)
            End Try
        Catch myerro As MySqlException
            MessageBox.Show("Erro ao conectar com a Base de dados : " & myerro.Message)
        End Try

Share this post

Link to post
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
Sign in to follow this  


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.