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 3 1811
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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
|
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,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
| |