|
-
May 29th, 2003, 03:38 PM
#1
Thread Starter
Fanatic Member
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.
-
May 29th, 2003, 03:57 PM
#2
Frenzied Member
You are getting a syntax error because of the parentesis on rowfilter.
Use this dvwItemNames.RowFilter = "SELECT DISTINCT Name"
-
May 29th, 2003, 04:02 PM
#3
Thread Starter
Fanatic Member
That didn't do it. I get "Syntax Error: Missing operand after 'DISTINCT' operator".
-
May 29th, 2003, 08:02 PM
#4
Frenzied Member
You are missing the table name from the Distinct statement. You might have to make another trip to the DB to get the Distinct names.
-
May 30th, 2003, 07:30 AM
#5
Thread Starter
Fanatic Member
That's what I was trying to avoid, as I already have all of the data in the datatable.
-
May 30th, 2003, 04:47 PM
#6
Frenzied Member
Why not just get the distinct names on the first call?
-
Jun 2nd, 2003, 07:01 AM
#7
Thread Starter
Fanatic Member
I need all the records, and I also need to get at distinct column x. I didn't want to do 2 queries if I already had the data already. What I am doing now is just looping through the returned results and adding new values for column x into an array (of course I have to loop through the array to make sure it isn't already added). I don't think this is the most efficient way, but it avoids another hit to the database and another datatable in the dataset (which actually might be a better solution).
-
Feb 28th, 2006, 09:54 AM
#8
New Member
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
-
Feb 28th, 2006, 06:42 PM
#9
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.
-
Feb 9th, 2010, 09:02 AM
#10
New Member
Re: DataView RowFilter - How to select distinct
use
.defaultview.totable(distinct as boolean, paramarray()) version to get distinct rows from table
-
Feb 9th, 2010, 03:07 PM
#11
Re: DataView RowFilter - How to select distinct
 Originally Posted by saurintravadi
use
.defaultview.totable(distinct as boolean, paramarray()) version to get distinct rows from table
Very cool
I've never thought of doing it this route before.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Mar 5th, 2010, 10:36 AM
#12
New Member
Re: DataView RowFilter - How to select distinct
 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
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
|