?
Solved

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

Posted on 2007-03-23
1
Medium Priority
?
1,097 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
1 Comment
 
LVL 15

Accepted Solution

by:
Thogek earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 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