cmtavares Posted April 18, 2013 at 03:44 PM Report #503834 Posted April 18, 2013 at 03:44 PM (edited) Boas pessoal, neste momento estou a desenvolver um programa de envio de newsletters, em que existe uma base de dados em SQL na qual estão registados todos os clientes. Existe também uma tabela com o nome de Grupos que tem como função relacionar um grupo a um cliente. A minha questão é a seguinte: Queria que ao selecionar o grupo numa combobox, mostra-se numa listbox todos os clientes relacionados com esse mesmo grupo que foi selecionado. o código que tenho é este: (não da erro mas não está a fazer o que pretendo) Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged Dim connectionString As String = "Password=irpasimpo;Persist Security Info=True;User ID=SA;Initial Catalog=OEI;Data Source=CARLOS-M\SQL" Dim connection As New SqlConnection(connectionString) connection.Open() 'Dim command As String = "Select Nome from Clientes where ID_GRUPO" Dim command As String = "select * from Grupos where ID_GRUPO='" & ComboBox1.Text & "' " If ComboBox1.SelectedText > "" Then Dim adpt As New SqlDataAdapter(command, connection) Dim myDataSet As New DataSet() adpt.Fill(myDataSet, "Clientes") Dim myDataTable As DataTable = myDataSet.Tables(0) Dim tempRow As DataRow For Each tempRow In myDataTable.Rows ListBox1.Items.Add((tempRow("Nome"))) Next End If End Sub Desde já o meu agradecimento Edited April 18, 2013 at 06:42 PM by ribeiro55
Leonardo Pereira Posted April 19, 2013 at 03:53 PM Report #504043 Posted April 19, 2013 at 03:53 PM O teu If não funciona assim, faz desta maneira: If ComboBox1.SelectedItem > "" Then ou If ComboBox1.SelectedItem <> Nothing
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