You can do this by building up a WHERE condition.
As the final SQL needs to be something along these lines:
SELECT EmpID, Name, Dept FROM Employees WHERE EmpID='001' OR EmpID='003';
Or, if your Database supports it:
SELECT EmpID, Name, Dept FROM Employees WHERE EmpID IN ('001', '003');
You just need to go through all your checkboxes and create the string using something like:
'Find each checked item
For Index = 0 to CheckListBox.ListCount - 1
If CheckListBox.Selected(Index) Then
'Append to an ID list string
If IDList <> "" Then IDList = IDList & ", "
IDList = IDList & "'" & Format(CheckListBox.ItemData(Index), "000") & "'"
End IF
Next
'Create the final SQL statement
If IDList <> "" Then
Query = "SELECT EmpID, Name, Dept FROM Employees WHERE EmpID IN (" & IDList & ");"
End If
Being any more specific than this is difficult without knowing what Database engine and library you're using, the checkbox control structure, or the database schema.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…