distinct

F

frazer

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.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
 
M

Martin Marinov

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
 
F

frazer

but it will still return duplicate groups.

Martin Marinov said:
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


and tha
 

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 groupid 1

Top