locked
Error: Value of type 'String' cannot be converted to '1-dimensional array of String RRS feed

  • Question

  • User-2143179829 posted

    Hi all can anyone tell me how to resolve this error my code is

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Roles.AddUsersToRole(DropDownList1.SelectedValue, DropDownList2.SelectedValue)
    Label1.Text = DropDownList1.SelectedValue + "Was Add to the" + DropDownList2.SelectedValue + "Role"
    Thursday, August 4, 2011 10:02 PM

Answers

  • User-1694870838 posted

    Hi,

    From your details,

    public static void AddUsersToRole(
    	string[] usernames,
    	string roleName
    )
    

    the first parameter is a 1-dimensional array, you can convert DropDownList1.SelectedValue to array first.

    Dim str As String() ={"DropDownList1.SelectedValue"}

    Roles.AddUsersToRole(str(0), DropDownList2.SelectedValue)

    Best Regards,

    Damon
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 10, 2011 4:34 AM

All replies

  • User388327963 posted

    DropDownList1.SelectedValue is a string where as the first argument is supposed to be ab array of strings. Check this out:

     

    http://msdn.microsoft.com/en-us/library/system.web.security.roles.adduserstorole.aspx

    Thursday, August 4, 2011 10:35 PM
  • User-1694870838 posted

    Hi,

    From your details,

    public static void AddUsersToRole(
    	string[] usernames,
    	string roleName
    )
    

    the first parameter is a 1-dimensional array, you can convert DropDownList1.SelectedValue to array first.

    Dim str As String() ={"DropDownList1.SelectedValue"}

    Roles.AddUsersToRole(str(0), DropDownList2.SelectedValue)

    Best Regards,

    Damon
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 10, 2011 4:34 AM