Distinct groupid

F

frazer

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.SecurityGroupMembership);

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.Row;
sb.Append(",'").Append(row.LoginName.Replace("'", "''")).Append('\'');
}
view.RowFilter = "LoginName not in (" + sb.ToString(1, sb.Length - 1) +
")";
Console.WriteLine(view.DataViewManager.DataSet.DataSetName);
}





thnx
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

distinct 3

Top