Jump to content

Vb.net + Checkedlistbox


Recommended Posts

Boa noite.

Gostaria de saber como é que posso fazer para inserir numa tabela mysql os itens selecionados numa  Checkedlistbox isto em vb.net. supondo que essa  Checkedlistbox tem bastantes itens.

Private Sub btnguardar3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar3.Click

        Dim data_adapter As Odbc.OdbcDataAdapter
        Dim data_table As New DataTable
        Dim i As Integer
        Dim j As Integer
        Dim nome As String

        Call ligar()
        i = 0

        For i = 0 To CheckedListBox1.CheckedItems.Count - 1

            nome = CheckedListBox1.GetItemText(CheckedListBox1.SelectedItems.Item(i))
            data_adapter = New Odbc.OdbcDataAdapter("select id_disc from disciplinas where disc_nome = '" & nome & "'", con)
            i = data_table.Rows(j).Item(0)
            cmd.CommandText = "insert into disciplinas_alunos (numero_mec,id_disc) values ('" & Me.txtnumero.Text & "','" & i & "')"

End Sub

este codigo que fiz por mais que selecione mais do que um item so me insere um e nao sei pq :wallbash:

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

  • 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.