SQL syntax question

V

VB Programmer

ASP.NET 2.0.....

How do I get all users (in aspnet_Users) that are not in the "member" role
(aspnet_Roles)?

Thanks.
 
K

Ken Cox - Microsoft MVP

Hi ???

Try this?

Ken
Microsoft MVP [ASP.NET]


<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
ShowRoleData()
End If
End Sub


Protected Sub ShowRoleData()
Dim Provider As SqlProfileProvider
Dim pageIndex As Integer = 0
Dim pageSize As Integer = 100
Provider = Profile.Providers _
("AspNetSqlProfileProvider")
GridView1.DataSource = Roles.GetUsersInRole _
("members")
GridView1.DataBind()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Role Info</title>
<style type="text/css">
body, span, label { font-size:large}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview id="GridView1" runat="server">
</asp:gridview>
</div>
</form>
</body>
</html>
 
V

VB Programmer

Thanks. But, how do I get those NOT in role "members"?

And... it's Robert. ;)

Thanks again Ken!

Ken Cox - Microsoft MVP said:
Hi ???

Try this?

Ken
Microsoft MVP [ASP.NET]


<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
ShowRoleData()
End If
End Sub


Protected Sub ShowRoleData()
Dim Provider As SqlProfileProvider
Dim pageIndex As Integer = 0
Dim pageSize As Integer = 100
Provider = Profile.Providers _
("AspNetSqlProfileProvider")
GridView1.DataSource = Roles.GetUsersInRole _
("members")
GridView1.DataBind()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Role Info</title>
<style type="text/css">
body, span, label { font-size:large}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview id="GridView1" runat="server">
</asp:gridview>
</div>
</form>
</body>
</html>

VB Programmer said:
ASP.NET 2.0.....

How do I get all users (in aspnet_Users) that are not in the "member"
role (aspnet_Roles)?

Thanks.
 
K

Ken Cox - Microsoft MVP

Hey Robert,

Sorry about that read it too fast. It looks like there's no built-in method
for that so it takes a little hack. This just loops through all the users,
checks them against the role and adds the non members to a datatable.

Protected Sub ShowRoleData()
Dim Provider As SqlProfileProvider
Dim pageIndex As Integer = 0
Dim pageSize As Integer = 100
Provider = Profile.Providers _
("AspNetSqlProfileProvider")
Dim memb As MembershipUser
Dim dt As New Data.DataTable
Dim dc As New Data.DataColumn
dc.ColumnName = "user"
dc.DataType = GetType(System.String)
dt.Columns.Add(dc)
For Each memb In Membership.GetAllUsers
If Not Roles.IsUserInRole(memb.UserName, "members") Then
dt.Rows.Add(memb.UserName)
End If
Next
GridView1.DataSource = dt
GridView1.DataBind()
End Sub

Does that work for you?

Ken
Microsoft MVP [ASP.NET]


VB Programmer said:
Thanks. But, how do I get those NOT in role "members"?

And... it's Robert. ;)

Thanks again Ken!

Ken Cox - Microsoft MVP said:
Hi ???

Try this?

Ken
Microsoft MVP [ASP.NET]


<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
ShowRoleData()
End If
End Sub


Protected Sub ShowRoleData()
Dim Provider As SqlProfileProvider
Dim pageIndex As Integer = 0
Dim pageSize As Integer = 100
Provider = Profile.Providers _
("AspNetSqlProfileProvider")
GridView1.DataSource = Roles.GetUsersInRole _
("members")
GridView1.DataBind()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Role Info</title>
<style type="text/css">
body, span, label { font-size:large}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview id="GridView1" runat="server">
</asp:gridview>
</div>
</form>
</body>
</html>

VB Programmer said:
ASP.NET 2.0.....

How do I get all users (in aspnet_Users) that are not in the "member"
role (aspnet_Roles)?

Thanks.
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top