Using SQL query you can use NOT IN or EXISTS/NOT EXISTS in your SELECT query.
Ex.
SELECT * FROM [tblStudent] WHERE StudentID NOT IN (1,2,3,4,5)
SELECT * FROM [tblResult] WHERE StudentID EXISTS (SELECT * FROM tblStudent WHERE Result='PASS')
In C#, you can use
String.Contains
method with array
string[] fruits = {"apple", "banana", "mango", "orange", "cherry", "grape"};
string fruit = "mango";
bool hasMango = fruits.Contains(fruit);
Also you can use loops to check the existence of values.