Friday, February 24, 2012

AMO: Convert string to Role and Role Member

Hi,

I have a functionality in my AMO that deletes role member from a specific role but first I must check if that role member is existing in that role before calling any delete.

This is the function that checks if role member is existing:

Function RoleContains(ByVal MyRole As Role, ByVal MemberName As String) As Boolean

For Each rm As RoleMember In MyRole.Members

If String.Compare(rm.Name, MemberName, True) = 0 Then

Return True

End If

Next

End Function

However, the one i will pass to the parameters are taken from the textbox of vb.net. so the data type is string and i'm having a problem passing this to Role object.

how can i do that?

cherriesh

The role collection includes a FindByName() method. So, if you were after a database role object, you can get a role object from it's name by doing something like:

myRole = db.Roles.FindByName("Test Role")

No comments:

Post a Comment