Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42427

Please I need help with this

$
0
0
Please I need help

I have a list of ClassID that is stored based on users multi select on a listview
For example ClassID might contain

301
302
303
304

Now I need to find InstructorID where classID matches all the value in the above list.
I am using this query

Code:

Dim assSQL = "Select InstructorID from ClassInstructors where ClassID = @P0"
            For i = 1 To classIDs.Count - 1
                assSQL &= " UNION Select InstructorID from ClassInstructors where ClassID = @P" & i.ToString
            Next

            Dim assCMD As New SqlCommand(assSQL)
            For i = 0 To classIDs.Count - 1
                assCMD.Parameters.Add(New SqlParameter With {.ParameterName = "@P" & i.ToString, .SqlDbType = SqlDbType.VarChar, .Size = 50, .Value = classIDs(i)})
            Next

But the problem is the query is returning InstructorID where ClassID matches any of the ClassIDs. I want it to return Instructor ID where ClassID matches all of the ClassIDs in the string.

Can someone help with this?

Viewing all articles
Browse latest Browse all 42427

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>