473,395 Members | 1,466 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,395 software developers and data experts.

Distinct groupid

hi
The following code is in c# but the same problem occrus even for vb.net.
any suggestions are welcome.

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 20 '05 #1
1 1510
Hi Frazer,

This a vb.net newsgroup not Csharp.

However maybe you can archieve what you want doing this
dv1 table groups
dv2 table users
dv3 table users

listbox1.datasource = dv1;
dv2.rowfilter = "Group = " + listbox1.selecteditem;
listbox2.datasource = dv2;
Create an "!= X And" or and "In" expression string from users in dv2
dv3.rowfilter = "Users " + expression string

I did not try it, however I see not much problems doing this (or something
like this).

I hope this helps?

Cor

hi
The following code is in c# but the same problem occrus even for vb.net.
any suggestions are welcome.

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 20 '05 #2

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...
3
by: frazer | last post by:
hi i have the following 2 typed datasets. 1."SecurityGroupMembership" LoginName GroupId 2."Users"
5
by: tamilan71 | last post by:
Hello All I have table with following fields: GroupId VisitDate 1 10/19/1993 1 11/24/1998 2 10/18/1993 2 10/29/1998 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,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.