Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:41:16+00:00 2026-06-16T04:41:16+00:00

I have a query which selects from the db where value=combobox.selectedtext. However, what I

  • 0

I have a query which selects from the db where value=combobox.selectedtext.

However, what I want to do is for the where value to check all values of the combobox.

Can someone offer advice as to how this would be done?

My sql query is this at the minute:

Dim sqlOpServ As String = ("SELECT DISTINCT col1, col2 from table1, table2 where test=test1 AND value= '" & combobox1.SelectedItem & "' ORDER BY col1 ASC")

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:41:18+00:00Added an answer on June 16, 2026 at 4:41 am

    I don’t have VS right know so I I will try you help you without trying my code:

     Dim sWhere as string=""
     For i = 0 To ComboBox1.Items.Count - 1
            sSelect = sSelect & " AND value='" & ComboBox1.Items(i) & "' "
     Next
    
     Dim sqlOpServ As String = ("SELECT DISTINCT col1, col2 from table1, table2 where test=test1 " & sWhere & " ORDER BY col1 ASC")
    

    After the comments:

       Dim sWhere As String = ""
    
        For i = 0 To ComboBox1.Items.Count - 1
            If i = 0 Then
                sWhere = " AND value='" & ComboBox1.Items(i).ToString & "' "
            Else
                sWhere = sWhere & " OR value='" & ComboBox1.Items(i).ToString & "' "
            End If
    
        Next
    
        Dim sqlOpServ As String = _
            ("SELECT DISTINCT col1, col2 from table1, table2 where test=test1 " & sWhere & " ORDER BY col1 ASC")
    

    If you have used a datatable to fill your combobox

        Dim table As DataTable = DirectCast(Me.ComboBox1.DataSource, DataTable)
        Dim sWhere As String = ""
    
        For i = 0 To ComboBox1.Items.Count - 1
            Dim displayItem As String = table.Rows(i)(ComboBox1.DisplayMember).ToString()
            ' Dim valueItem As String = table.Rows(i)(ComboBox1.ValueMember).ToString() 'if you need at some point the value you can use this
    
            If i = 0 Then
                sWhere = " AND value='" & displayItem & "' "
            Else
                sWhere = sWhere & " OR value='" & displayItem & "' "
            End If
    
        Next
    
        Dim sqlOpServ As String = _
            ("SELECT DISTINCT col1, col2 from table1, table2 where test=test1 " & sWhere & " ORDER BY col1 ASC")
    

    I hope I helped

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which looks like this: SELECT LossCost, CoverageID FROM BGILossCost] WHERE
I have the following query which have 1000 rows select staffdiscountstartdate,datediff(day,groupstartdate,staffdiscountstartdate), EmployeeID from tblEmployees
I have the query to select some columns from two tables, which must contain
I have the following which works in SQL Query Analyzer . select oh.* from
I have 6 columns in a table. I have a select query which selects
I have a query that is created in VBA and selects column information from
i have a search query which will retrieve information from 3 tables i made
I have this query which works perfectly: SELECT * FROM Customer WHERE SacCode IN
I have this query which works perfectly: SELECT * FROM Customer WHERE SacCode IN
I have the following query that selects some records from the database: $select_person =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.