Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Good morning. I'm crushing my head to find a way to simulate the "IN (SELECT" sql clause.
I have two tables in a dataset and a relation between them (i. e. Orders and Articles). I neeed to filter orders containing a given article (by Id or by Description)

The structure I'm trying to reproduce is:
SELECT * FROM Orders WHERE idOrder IN (SELECT idOrder FROM Articles WHERE Articles.Description like '%something%')

Can anyone help me?

What I have tried:

I tried to search documentation in internet... without success...
Posted
Updated 4-Jun-23 22:24pm
v2
Comments
jekin77 1-Jun-23 5:53am    
try with LINQ by using contains method

https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/queries-in-linq-to-dataset
https://dotnettutorials.net/lesson/linq-contains-method/
Andre Oosthuizen 1-Jun-23 6:19am    
Show us your current SQL statement for easier understanding. Use the 'Improve Question' to edit your question.
[no name] 1-Jun-23 11:33am    
You select the articles (by "id or description"); then retrieve the related order (related, I assume, on "order id"); which implies not "articles"; but "order items" that reference an article.
PIEBALDconsult 1-Jun-23 13:22pm    
Use the RowFilter property of the DataTable's DefaultView ( DataView ).
dataset.Tables [ " ... " ].DefaultView.RowFilter = " ... " ;
Jean Ferre 3-Jun-23 8:38am    
What have you tried to do in your code so far? Could you improve your question and add some code in "What I have tried" section, please

1 solution

I'd suggest to read this: Filtering with DataView (LINQ to DataSet) - ADO.NET | Microsoft Learn[^]

If you would like to filter the dataset using IN clause, then you have to use Any[^] method.

See:
C#
List<int> myset = Enumerable.Range(0,100).ToList();
List<int> itemstofind = new List<int>(){1,5,19,28,37,42,69,88,15,9,33,17,99};

List<int> result = myset.Where(x => itemstofind.Any(y => y.Equals(x))).ToList();
foreach(int i in result)
	Console.WriteLine(i);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900