Sql Role Provider

81 views Asked by At

I am new to asp.net and I am trying to implement my role provider, actually sql role provider. In my Role Provider I added:

 public void AddUsersToRole(string[] usernames, string[] rolenames)
        {
            SqlConnection conn =
                 new SqlConnection(
                     ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("INSERT INTO Users " +
                                               " (Username, Role) " +
                                               " Values(?, ?)", conn);
            SqlParameter Username = cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 50);
            SqlParameter Role = cmd.Parameters.Add("@Role", SqlDbType.NVarChar, 50);


            try
            {
                conn.Open();

                foreach (string username in usernames)
                {
                    foreach (string rolename in rolenames)
                    {
                        Username.Value = username;
                        Role.Value = rolename;
                        cmd.ExecuteNonQuery();
                    }
                }
            }

But when I put in my login page the following:

                    Roles.AddUsersToRole(TextBoxUsername.Text, DropDownListRole.SelectedItem.Value);

  

And when I build it I got an error.

Please help, tnx in advance.

1

There are 1 answers

2
Mert On BEST ANSWER

your method expecting string[] but you are providing string.

Roles.AddUsersToRole(TextBoxUsername.Text, DropDownListRole.SelectedItem.Value);

public void AddUsersToRole(string[] usernames, string[] rolenames)

solution:

Roles.AddUsersToRole(new string[] { TextBoxUsername.Text }, new string[] { DropDownListRole.SelectedItem.Value });