heliumgas Posted April 21, 2007 at 03:30 AM Report Share #95004 Posted April 21, 2007 at 03:30 AM 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) data_adapter.Fill(data_table) i = data_table.Rows(j).Item(0) cmd.CommandText = "insert into disciplinas_alunos (numero_mec,id_disc) values ('" & Me.txtnumero.Text & "','" & i & "')" cmd.ExecuteNonQuery() Next End Sub este codigo que fiz por mais que selecione mais do que um item so me insere um e nao sei pq Link to comment Share on other sites More sharing options...
frodo Posted April 23, 2007 at 11:28 AM Report Share #95376 Posted April 23, 2007 at 11:28 AM Não vi o teu código com muita atenção mas não vejo a variável j a ser inicializada nem a fazer loop. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now