473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

distinct

hi
i have the following 2 typed datasets.
1."SecurityGroupMembership"
LoginName
GroupId
2."Users"
LoginName
Password
Fname

Sample data
loginname groupid
user2 8
user1 1
user1 2

i have 2 listboxes selected and notselected
i populate selected list box with loginnames of users of a particular group
in this case 8
and
not selected list with loginnames of users not belonging to group 8. but to
other groups.

listbox2 displays all usernames correctly

since a user can belong to more than 1 group. i get duplicate records.
to eliminate these i use filterview.

but i dont want to use filter view coz the list of users is very long and i
want to optimise this code.
is there any way to do like a distinct on listbox2 so that i can have a
rowfilter groupid <> 8
so that i get only the distinct users that dont belong to group8.
currently if i do this i get user1 twice in the not selected list.

this.sqlConnection1.Open();
this.sqlDataAdapter2.Fill(this.users1.User);
this.sqlDataAdapter1.Fill(this.memberships1.Securi tyGroupMembership);

DataView selectedView = new
DataView(this.memberships1.SecurityGroupMembership );
selectedView.RowFilter = "GroupId = " + this.groupId.ToString();

DataView notSelectedView = new DataView(this.users1.User);

this.listBox1.DataSource = notSelectedView;
this.listBox1.DisplayMember = "LoginName";
this.listBox2.DataSource = selectedView;
this.listBox2.DisplayMember = "LoginName";

FilterView(notSelectedView);

/*this is what i want to change, i would like to optimise this part so that
i can do something like a distinct.*/

private void FilterView(DataView view)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
DataView selectedView = (DataView)this.listBox2.DataSource;
foreach(DataRowView rowView in selectedView)
{
Memberships.SecurityGroupMembershipRow row =
(Memberships.SecurityGroupMembershipRow)rowView.Ro w;
sb.Append(",'").Append(row.LoginName.Replace("'", "''")).Append('\'');
}
view.RowFilter = "LoginName not in (" + sb.ToString(1, sb.Length - 1) +
")";
Console.WriteLine(view.DataViewManager.DataSet.Dat aSetName);
}

thnx
Nov 16 '05 #1
2 3638
but it will still return duplicate groups.

"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can use
selectedView.RowFilter = " NOT GroupId = " + this.groupId.ToString();

in the RowFilter you can add statement just like in the stored procedure

Regards
Martin Marinov
"frazer" <ic***@hotmail.com> wrote in message
news:#r*************@TK2MSFTNGP10.phx.gbl...
hi
i have the following 2 typed datasets.
1."SecurityGroupMembership"
LoginName
GroupId
2."Users"
LoginName
Password
Fname

Sample data
loginname groupid
user2 8
user1 1
user1 2

i have 2 listboxes selected and notselected
i populate selected list box with loginnames of users of a particular group
in this case 8
and
not selected list with loginnames of users not belonging to group 8. but

to
other groups.

listbox2 displays all usernames correctly

since a user can belong to more than 1 group. i get duplicate records.
to eliminate these i use filterview.

but i dont want to use filter view coz the list of users is very long and i
want to optimise this code.
is there any way to do like a distinct on listbox2 so that i can have a
rowfilter groupid <> 8
so that i get only the distinct users that dont belong to group8.
currently if i do this i get user1 twice in the not selected list.

this.sqlConnection1.Open();
this.sqlDataAdapter2.Fill(this.users1.User);
this.sqlDataAdapter1.Fill(this.memberships1.Securi tyGroupMembership);

DataView selectedView = new
DataView(this.memberships1.SecurityGroupMembership );
selectedView.RowFilter = "GroupId = " + this.groupId.ToString();

DataView notSelectedView = new DataView(this.users1.User);

this.listBox1.DataSource = notSelectedView;
this.listBox1.DisplayMember = "LoginName";
this.listBox2.DataSource = selectedView;
this.listBox2.DisplayMember = "LoginName";

FilterView(notSelectedView);

/*this is what i want to change, i would like to optimise this part so
tha t
i can do something like a distinct.*/

private void FilterView(DataView view)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
DataView selectedView = (DataView)this.listBox2.DataSource;
foreach(DataRowView rowView in selectedView)
{
Memberships.SecurityGroupMembershipRow row =
(Memberships.SecurityGroupMembershipRow)rowView.Ro w;
sb.Append(",'").Append(row.LoginName.Replace("'",

"''")).Append('\''); }
view.RowFilter = "LoginName not in (" + sb.ToString(1, sb.Length - 1) + ")";
Console.WriteLine(view.DataViewManager.DataSet.Dat aSetName);
}

thnx


Nov 16 '05 #2
Unfortunatelly for some reason i couldn't see all of the message and though
that you want to use just to use RowFilter and implement in it Not.
To perform the distinct on dataset, check this article :
http://support.microsoft.com/default...b;EN-US;325684

Regards
Martin

"frazer" <ic***@hotmail.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
but it will still return duplicate groups.

"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can use
selectedView.RowFilter = " NOT GroupId = " + this.groupId.ToString();

in the RowFilter you can add statement just like in the stored procedure

Regards
Martin Marinov
"frazer" <ic***@hotmail.com> wrote in message
news:#r*************@TK2MSFTNGP10.phx.gbl...
hi
i have the following 2 typed datasets.
1."SecurityGroupMembership"
LoginName
GroupId
2."Users"
LoginName
Password
Fname

Sample data
loginname groupid
user2 8
user1 1
user1 2

i have 2 listboxes selected and notselected
i populate selected list box with loginnames of users of a particular group
in this case 8
and
not selected list with loginnames of users not belonging to group 8. but
to
other groups.

listbox2 displays all usernames correctly

since a user can belong to more than 1 group. i get duplicate
records. to eliminate these i use filterview.

but i dont want to use filter view coz the list of users is very long

and
i
want to optimise this code.
is there any way to do like a distinct on listbox2 so that i can have a rowfilter groupid <> 8
so that i get only the distinct users that dont belong to group8.
currently if i do this i get user1 twice in the not selected list.

this.sqlConnection1.Open();
this.sqlDataAdapter2.Fill(this.users1.User);
this.sqlDataAdapter1.Fill(this.memberships1.Securi tyGroupMembership);
DataView selectedView = new
DataView(this.memberships1.SecurityGroupMembership );
selectedView.RowFilter = "GroupId = " + this.groupId.ToString();

DataView notSelectedView = new DataView(this.users1.User);

this.listBox1.DataSource = notSelectedView;
this.listBox1.DisplayMember = "LoginName";
this.listBox2.DataSource = selectedView;
this.listBox2.DisplayMember = "LoginName";

FilterView(notSelectedView);

/*this is what i want to change, i would like to optimise this part so

tha
t
i can do something like a distinct.*/

private void FilterView(DataView view)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
DataView selectedView = (DataView)this.listBox2.DataSource;
foreach(DataRowView rowView in selectedView)
{
Memberships.SecurityGroupMembershipRow row =
(Memberships.SecurityGroupMembershipRow)rowView.Ro w;
sb.Append(",'").Append(row.LoginName.Replace("'",

"''")).Append('\''); }
view.RowFilter = "LoginName not in (" + sb.ToString(1, sb.Length -
1) + ")";
Console.WriteLine(view.DataViewManager.DataSet.Dat aSetName);
}

thnx



Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ben | last post by:
This is a PHP / MySQL kind of question. I am making a script which simply pulls information from a database and displays it on screen. BUT there will be entries where fields could be the same, and...
5
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
4
by: Johnson, Shaunn | last post by:
Howdy: Can someone tell what the difference (and why you would use it) is between the following: select distinct on (col_1, col_2), col_1, col_2, col_3
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
3
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada...
6
by: Bob Stearns | last post by:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message: DB2 SQL error: SQLCODE: -214,...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
2
by: Techhead | last post by:
I need to run a SELECT DISTINCT query across multiple fields, but I need to add another field that is NON-DISTINCT to my record set. Here is my query: SELECT DISTINCT lastname, firstname,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.