
Best Answer lespauled , 04 July 2013 - 12:54 PM
This wont help your issue, but do an inner join instead of the in clause. It looks like your double quotes are out of sync
Go to the full post
WendellHarper - Dec 06 2020 01:21 PM
WendellHarper - Dec 06 2020 01:14 PM
pindo - Jul 23 2020 01:33 AM
Siten0308 - Jun 20 2019 01:43 PM
johnnylo - Apr 23 2019 07:49 AM
Best Answer lespauled , 04 July 2013 - 12:54 PM
This wont help your issue, but do an inner join instead of the in clause. It looks like your double quotes are out of sync
Go to the full postPosted 04 July 2013 - 12:10 PM
Hi all,
I'm trying to figure out, why after clicking once again on my combobox, next combobox remember items from previous selection.
I have 7 comboboxes (items for cb's are storen in SQL table). For each I have Sub to fill it with the items, like this:
Sub fillAdditional() Dim var As String = Convert.ToString(cbAccount.SelectedItem) Dim var2 As String = Convert.ToString(cbTower.SelectedItem) Dim var3 As String = Convert.ToString(cbProcess.SelectedItem) strsql = "Select Distinct Additional from tblAdministratorData where AccIc in ( Select AID from tblAccount)" '((TimerAccount like '%" + var + "%') AND (TimerTower like '%" + var2 + "%') and (TimerProcess like '%" + var3 + "%'))" Dim acscmd As New SqlCommand acscmd.CommandText = strsql acscmd.Connection = cn acsdr = acscmd.ExecuteReader While (acsdr.Read()) Me.cbAdditional.Items.Add(acsdr("Additional")) End While acscmd.Dispose() acsdr.Close() End Sub
I'm calling each after Combobox_SelectedIndexChange like:
Me.fillAdditional()
I was trying to do it, by adding
cbTower.SelectedIndex = cbTower.FindString(cbAccount.SelectedText)
to Combobox_SelectedIndexChange, but no value added...
Could someone tell me, what I'm doing wrong?
Thank you in advance!
Best Regards
Matt
Posted 04 July 2013 - 12:54 PM Best Answer
This wont help your issue, but do an inner join instead of the in clause. It looks like your double quotes are out of sync
Posted 04 July 2013 - 12:55 PM
Putting the call to the sub in the selectedindexchanged event would be bad practice for this. What you are essentially doing is adding the result of your query to the combobox and then when the user selects an item, you're adding the results of your query to the combobox. However, there is already data there so it's duplicating. No you could easily clear your combobox right before your While loop starts but that would probably have issues with the selectedindex that the user selects when you clear to repopulate.
I would suggest populating the comboboxes based on the query either during the loading of the form or right after you know how you want to populate them and leave it alone until you have deemed it necessary to re-fill (clear and fill) based on newly added options for the user.
Posted 05 July 2013 - 12:24 AM
Hi, thanks for your answer.
I'm trying to do that, but I don't know where to put 'clear', because I'm calling me.fill'Combo' in SelectedIndexChanged event on previous Combobox...I cannot upload all data on_load, because my filling subs are using previous selection as a variant so....
Ehh, I have no idea how to solve it...
Posted 05 July 2013 - 05:54 AM
Okay, I've done this. I had an error in the table
Thank you for your help!