|
-
December 14th, 2010, 07:23 AM
#1
Filter datatable using an array of values?
I have a datatable called dt which includes a column called type
I have a string array called typestringarray with about 15 members
I want to create a new datatable from the rows where type is a member of typestringarray
here's a simplified example of my problem:
dt
id type
1 red
2 blue
3 orange
4 green
5 pink
6 green
typestringarray = {"red", "blue", "green")
so my new table would be
id type
1 red
2 blue
4 green
6 green
I'm not sure how to start.
defaultview.rowfilter doesn't look right, as my filter would have 15 or more OR clauses.
There must be a really simple answer that I'm missing?
I'm using .NET Framework 3.5
I'm planning to be spontaneous tomorrow
-
December 14th, 2010, 01:49 PM
#2
Re: Filter datatable using an array of values?
Nope, you'd need 15 SQL statements, but you could use a LOOP
-
December 19th, 2010, 12:19 AM
#3
Re: Filter datatable using an array of values?
Try:
{"red", "blue", "green"}.Contains(type)
as you itterate through dt
-
December 21st, 2010, 01:02 PM
#4
Re: Filter datatable using an array of values?
You should be able to use an IN clause... no?
Code:
.RowFilrer = "Field IN ('Red','Green','Blue')"
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|