Solved

Value of type 'String' cannot be converted to '1-dimensional array of String'

Posted on 2007-03-23
1
1,049 Views
Last Modified: 2008-01-09
I want to pass string values from my listbox to a function which is located in another file, I get an error when i try to pass values in
AddUsersToRoles()

Please Advice:

        Dim lstItem As ListItem
        For Each SelectedItem In CType(SelectRoles.FindControl("AvailableRoles"), ListBox).Items
            If lstItem .Selected = True Then
                MyRole= lstItem .Value
                System.Web.Security.Roles.AddUsersToRoles(CreateUserWizard1.UserName, MyRole)
            End If
        Next

Error: Value of type 'String' cannot be converted to '1-dimensional array of String'
this errors is in: AddUsersToRoles(CreateUserWizard1.UserName, MyRole)

AddUsersToRoles Object Browswer:
Public Shared Sub AddUsersToRoles(ByVal usernames() As String, ByVal roleNames() As String)
     Member of: System.Web.Security.Roles
Summary:
Adds the specified users to the specified roles.

Parameters:
roleNames: A string array of role names to add the specified user names to.
usernames: A string array of user names to add to the specified roles.

Exceptions:
System.Configuration.Provider.ProviderException: Role management is not enabled.
System.ArgumentNullException: One of the roles in roleNames is null.-or-One of the users in usernames is null.
System.ArgumentException: One of the roles in roleNames is an empty string or contains a comma (,).-or-One of the users in usernames is an empty string or contains a comma (,).-or-roleNames contains a duplicate element.-or-usernames contains a duplicate element.

0
Comment
Question by:Padre_Corleone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
Thogek earned 500 total points
ID: 18784538
It sounds like both parameters of the System.Web.Security.Roles.AddUsersToRoles method are arrays (see http://msdn2.microsoft.com/en-us/library/system.web.security.roles.adduserstoroles(VS.80).aspx), but you're trying to pass it single objects instead of arrays, so it's complaining that it can't convert them for you.

You could patch the difference with something like:

    System.Web.Security.Roles.AddUsersToRoles(New String() { CreateUserWizard1.UserName}, New String() { MyRole })
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question