DataView RowFilter - How to select distinct
Is it possible to select distinct in the rowfilter method?
I have something like:
VB Code:
'Create a data view so we can get each items name
Dim dvwItemNames As New DataView(dtlItems)
dvwItemNames.RowFilter() = "SELECT DISTINCT Name"
This gives me a syntax error exception. I tried just "Distinct Name" but this had the same result. "Name" is the column name.
Any ideas? I would rather do it this way then looping through the entire table and putting the name in an array list or something.
Thanks.
Re: DataView RowFilter - How to select distinct
Hi,
one thing to mention about the dataview, it doesn't support selecting distinct values, that's why you get syntax error, the only thing it supports is selecting rows based on a certain criteria, like "id = 334" or "name like 'MA%'"
if you want to select the distinct values, you must make a customized function that returns a new table with distinct values only, then you make the dataview on the new table.
You can find full converage for this topic in the following link
http://www.dotnet247.com/247referenc...m/?kbid=325684
Re: DataView RowFilter - How to select distinct
The RowFilter property is equivalent to a WHERE clause from an SQL query, just like the Sort property is equivalent to an ORDER BY clause. There's no DISTINCT in a WHERE clause, only conditions. Also, RowFilter does not support the entire SQL specification. See the help/MSDN topic for DataColumn.Expression for details on what is supported.
Re: DataView RowFilter - How to select distinct
use
.defaultview.totable(distinct as boolean, paramarray()) version to get distinct rows from table
Re: DataView RowFilter - How to select distinct
Quote:
Originally Posted by
saurintravadi
use
.defaultview.totable(distinct as boolean, paramarray()) version to get distinct rows from table
Very cool :thumb:
I've never thought of doing it this route before.
Re: DataView RowFilter - How to select distinct
Quote:
Originally Posted by
saurintravadi
use
.defaultview.totable(distinct as boolean, paramarray()) version to get distinct rows from table
How do you use this code snippet? Where do you insert this?
Thanks,
Damon