Link to home
Start Free TrialLog in
Avatar of rmartin15
rmartin15

asked on

Build SQL String from selectedItems in ListBox in VB.net

VB.Net 2003

Multi-Selection List Box
Datatype String    Domain Name  e.g.  aol.com,hotmail.com
lstDomainName  is the name of the control

I have a list box with different domain names, and also a selection of the text "All"
I'd like to generate an email list based on the domains the user selects, or based on all domains if the user selects "All"

The resulting SQL statment should end up something like this  

Select EmailAddress,Created   ' If the customer selects a domain or multiple domains
From tblUsers
Where Domain = Whats in lstDomainName

or Select EmailAddress,Created  ' If the customer selects All
From tbl Users


Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of ZeonFlash
ZeonFlash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rmartin15
rmartin15

ASKER

How do I test if "All" was selected in lstDomainName ?   It is the first item in the list, and is also the assigned default value when the form is loaded, or is reset.
In that case, you could simply check if selIndices(0) = 0.  Since "All" is the first item, it will have index 0...and since the index collection is in order, you'll be able to look in slot 0 every time to see if it is chosen.
Thanks