cmtavares Posted April 19, 2013 at 12:05 AM Report #503923 Posted April 19, 2013 at 12:05 AM Boas pessoal, neste momento estou com um pequeno problema que é o seguinte. Estou a criar um pequeno aplicativo que tem como função envio de newsletter's, em que esse mesmo aplicativo da para criar/ editar/ e remover clientes. Existe um base de dados em sql e agora tenho a função de poder criar grupos de clientes, mas a minha duvida é: Estou a mostrar numa comboBox todos os nomes dos grupos já existentes e queria que ao selecionar um desses grupos mostra'se os clientes que pertencem ao mesmo numa listbox. Agradeço desde já a vossa ajuda!
Leonardo Pereira Posted April 19, 2013 at 03:27 PM Report #504035 Posted April 19, 2013 at 03:27 PM Mostra as tuas tabelas da base de dados, isso resolve-se com um filtro
cmtavares Posted April 19, 2013 at 03:59 PM Author Report #504048 Posted April 19, 2013 at 03:59 PM eu ja tenho um filtro na combobox mas nao esta a trabalhar combenientemente
Nelson Sousa Posted April 19, 2013 at 05:07 PM Report #504064 Posted April 19, 2013 at 05:07 PM Olá, Carrega sua listbox no evento SelectionchangeCommited, ou no Validated da combobox. Um Abraço, Nelson Sousa
cmtavares Posted April 20, 2013 at 03:06 PM Author Report #504165 Posted April 20, 2013 at 03:06 PM Obrigada desde já a vossa ajuda! eu já tenho algum código mas neste momento não está a a fazer o que pretendo! 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 Grupos where ID_GRUPO'" & Me.ComboBox1.SelectedText & "' " Dim adpt As New SqlDataAdapter(command, connection) Dim myDataSet As New DataSet() adpt.Fill(myDataSet, "Nome") Dim myDataTable As DataTable = myDataSet.Tables(0) Dim tempRow As DataRow For Each tempRow In myDataTable.Rows ListBox1.Items.Add((tempRow("Nome"))) Next Se conseguirem saber o que posso fazer agradeço imenso
Leonardo Pereira Posted April 22, 2013 at 08:55 AM Report #504268 Posted April 22, 2013 at 08:55 AM experimenta trocar esta linha Dim command As String = "Select Nome from Grupos where ID_GRUPO'" & Me.ComboBox1.SelectedText & "' " por esta Dim command As String = "Select Nome from Grupos where ID_GRUPO'" & Me.ComboBox1.SelectedItem & "' "
cmtavares Posted April 22, 2013 at 05:32 PM Author Report #504374 Posted April 22, 2013 at 05:32 PM Boa tarde, já fiz essa troca e não dá a mesma! não mostra nada! Acho que tem que ser mesmo a parir da selectText para poder fazer uma comparação de valores para depois conseguir obter o clientes respetivos daquele grupo. Agora estou indeciso de será ou não isso
Nelson Sousa Posted April 23, 2013 at 10:44 AM Report #504485 Posted April 23, 2013 at 10:44 AM Olá, Dim command As String = "Select Nome from Grupos where ID_GRUPO='" & Me.ComboBox1.SelectedText & "' " Nos informe o evento onde está executando este código. Um Abraço, Nelson Sousa
cmtavares Posted April 24, 2013 at 04:08 PM Author Report #504693 Posted April 24, 2013 at 04:08 PM Boas, o evento onde esta a ser excutado e Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Nelson Sousa Posted April 24, 2013 at 05:40 PM Report #504710 Posted April 24, 2013 at 05:40 PM Olá, Mude para o evento VALIDATED ou para SELECTIonchangeCOMITTED. Observe a mudança que fiz no código acima. Um Abraço, Nelson Sousa
acao Posted April 24, 2013 at 11:04 PM Report #504737 Posted April 24, 2013 at 11:04 PM boas não será melhor indicar como são criados os grupos e como estão relacionados com os clientes. cumps acao
cmtavares Posted April 29, 2013 at 02:15 PM Author Report #505180 Posted April 29, 2013 at 02:15 PM boas não será melhor indicar como são criados os grupos e como estão relacionados com os clientes. cumps acao boas, como assim não estou a perceber !
cmtavares Posted April 29, 2013 at 04:42 PM Author Report #505200 Posted April 29, 2013 at 04:42 PM http://img6.imageshack.us/img6/395/imagembgl.jpg Boas está ai uma imagem do design do programa o objetico é ao seleccionar um cliente da comboBox na listbox a baixo que esta vazia, mostrar os clientes pertencentes a esse mesmo grupo selecionado. Private Sub ComboBox1_SelectedIndex(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 variavel As String Dim command As String = "select Nome from Clientes where ID_GRUPO='" & Me.ComboBox1.SelectedItem & "' " MessageBox.Show(ComboBox1.SelectedItem) If ComboBox1.SelectedItem > "" Then Dim adpt As New SqlDataAdapter(command, connection) Dim myDataSet As New DataSet() adpt.Fill(myDataSet, "ID_GRUPO") 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 Se me poderem ajudar agradeço
acao Posted April 29, 2013 at 09:42 PM Report #505235 Posted April 29, 2013 at 09:42 PM boas, como assim não estou a perceber ! era a estrutura da basedados referente à questão. cumps acao
cmtavares Posted April 29, 2013 at 11:43 PM Author Report #505262 Posted April 29, 2013 at 11:43 PM Em 29/04/2013 às 23:42, acao disse: era a estrutura da basedados referente à questão. cumps acao http://img9.imageshack.us/img9/237/imageeetl.jpg é isto que pretendes?
Leonardo Pereira Posted April 30, 2013 at 08:32 AM Report #505280 Posted April 30, 2013 at 08:32 AM (edited) Isto deve funcionar 😉 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 FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " If ComboBox1.SelectedItem > "" Then Dim Reader As SqlDataReader = command.executeReader() If reader.HasRows Then while Reader.Read() ListBox1.Items.Add(reader.item("Nome")) End While End If End If Cumps PS : SelectedText é diferente de SelectedItem 😉 e qualquer dúvida avisa Edited April 30, 2013 at 01:57 PM by Leonardo Pereira
acao Posted April 30, 2013 at 01:35 PM Report #505313 Posted April 30, 2013 at 01:35 PM (edited) boas se no post anterior não deu! tenta assim, não foi testado Dim command As String = "SELECT Nome FROM Clientes WHERE ID_GRUPO = ("SELECT ID_GRUPO FROM Grupos Where Nome = '" & ComboBox1.SelectedText & "' ")" verifica nomes de tabelas e campo, maiúsculas e minúsculas fazem diferenca, cumps acao Edited April 30, 2013 at 01:53 PM by acao
cmtavares Posted April 30, 2013 at 02:40 PM Author Report #505320 Posted April 30, 2013 at 02:40 PM Isto deve funcionar 😉 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 FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " If ComboBox1.SelectedItem > "" Then Dim Reader As SqlDataReader = command.executeReader() If reader.HasRows Then while Reader.Read() ListBox1.Items.Add(reader.item("Nome")) End While End If End If Cumps PS : SelectedText é diferente de SelectedItem 😉 e qualquer dúvida avisa 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 FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " If ComboBox1.SelectedItem > "" Then Dim Reader As SqlDataReader = command.executeReader() If Reader.HasRows Then While Reader.Read() ListBox1.Items.Add(Reader.Item("Nome")) End While End If End If End Sub Dim Reader As SqlDataReader = command.executeReader() -> esta linha diz-me que "executeReader is not member of string" ainda não percebi bem porque! cump
Leonardo Pereira Posted April 30, 2013 at 04:10 PM Report #505340 Posted April 30, 2013 at 04:10 PM (edited) 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 FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " If ComboBox1.SelectedItem > "" Then Dim Reader As SqlDataReader = command.executeReader() If Reader.HasRows Then While Reader.Read() ListBox1.Items.Add(Reader.Item("Nome")) End While End If End If End Sub Dim Reader As SqlDataReader = command.executeReader() -> esta linha diz-me que "executeReader is not member of string" ainda não percebi bem porque! cump porque me esqueci de uma linha de código xD a seguir a Dim command As String = "SELECT Nome FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " coloca Dim ExecuteComand = SqlCommand(command, connection) e depois altereas a linha Dim Reader As SqlDataReader = command.executeReader() por esta Dim Reader As SqlDataReader = ExecuteComand.executeReader() assim já vai aceitar o ExecuteReader 😉 Edited April 30, 2013 at 04:12 PM by Leonardo Pereira
cmtavares Posted April 30, 2013 at 05:59 PM Author Report #505355 Posted April 30, 2013 at 05:59 PM porque me esqueci de uma linha de código xD a seguir a Dim command As String = "SELECT Nome FROMClientes WHERE ID_GRUPO = (SELECT ID_GRUPO FROM Grupos WHERE Nome ='" & ComboBox1.SelectedItem & "') " coloca Dim ExecuteComand = SqlCommand(command, connection) e depois altereas a linha Dim Reader As SqlDataReader = command.executeReader() por esta Dim Reader As SqlDataReader = ExecuteComand.executeReader() assim já vai aceitar o ExecuteReader 😉 Obrigada finalmente já está a dar 🙂 Finalmente já está a fazer o que pretendo mas já agora só mais uma pequena dúvida. seleciono um grupo e já aparece os clientes repetivos mas se selecionar novamente um grupo diferente os clientes do antigo grupo permanecem na listbox, isso e so fazer um clean a listbox?
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