Solved

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

Posted on 2007-03-23
1
1,033 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 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now