locked
How to insert membership role in table? RRS feed

  • Question

  • User481677910 posted

    Hi,

    I would like to customer to insert membership role while submitting form for order.

    How can  we insert membership role into table let's say table name is "order"

    Like

                cmd.Parameters.AddWithValue("@role", Membership.GetUser(User.Identity.Name)

    Kindly help thanks

    Monday, October 28, 2019 7:03 PM

All replies

  • User-943250815 posted

    An user can be assigned to single or multiple roles. You can get all user roles with Roles.GetRolesForUser.
    Take a look here https://docs.microsoft.com/en-us/dotnet/api/system.web.security.roles.getrolesforuser?view=netframework-4.8

    Monday, October 28, 2019 8:34 PM
  • User-1780421697 posted
    try
        {
          string[] rolesArray = Roles.GetRolesForUser();
          //Get role and use it, i have selected the first role in array in example
    cmd.Parameters.AddWithValue("@role", rolesArray[0]); //OR you can use LINQ to find role in array what you looking for and select it } catch (HttpException e) { //Label Msg.Text = "There is no current logged on user. Role information cannot be retrieved."; return; }

    Tuesday, October 29, 2019 4:14 AM
  • User288213138 posted

    Hi new2world2015,

    I would like to customer to insert membership role while submitting form for order.

    How can  we insert membership role into table let's say table name is "order"

    According to your description, I couldn’t understand your requirement clearly.

    what is insert membership role into table?

    cmd.Parameters.AddWithValue("@role", Membership.GetUser(User.Identity.Name)

    Do you want to add a value to the parameter of role in the table?

    If this is your requirement, I suggest you could refer to this link: https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlparametercollection.addwithvalue?view=netframework-4.8

    If I misunderstand your requirement, please post more details information about your requirement.

    Best regards,

    Sam

    Tuesday, October 29, 2019 6:46 AM
  • User481677910 posted

    Hi new2world2015,

    new2world2015

    I would like to customer to insert membership role while submitting form for order.

    How can  we insert membership role into table let's say table name is "order"

    According to your description, I couldn’t understand your requirement clearly.

    what is insert membership role into table?

    new2world2015

    cmd.Parameters.AddWithValue("@role", Membership.GetUser(User.Identity.Name)

    Do you want to add a value to the parameter of role in the table?

    If this is your requirement, I suggest you could refer to this link: https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlparametercollection.addwithvalue?view=netframework-4.8

    If I misunderstand your requirement, please post more details information about your requirement.

    Best regards,

    Sam

    Let says I have a member who  has role as premium member  and he is submitting form in order table.

    Now how can his role as premium member insert in order table.

    I am using membership database.

    Thursday, October 31, 2019 12:37 AM
  • User481677910 posted

    Khuram.Shahzad

    try
        {
          string[] rolesArray = Roles.GetRolesForUser();
          //Get role and use it, i have selected the first role in array in example
           cmd.Parameters.AddWithValue("@role", rolesArray[0]); //OR you can use LINQ to find role in array what you looking for and select it
        }
        catch (HttpException e)
        {
          //Label
          Msg.Text = "There is no current logged on user. Role information cannot be retrieved.";
          return;
        }
    

    I will try this one and let you know Thanks

    Thursday, October 31, 2019 2:34 AM
  • User288213138 posted

    Hi new2world2015,

    string[] rolesArray = Roles.GetRolesForUser();

    The GetRolesForUser() method is get a list of the roles that the currently logged-on user is in.

    https://docs.microsoft.com/en-us/dotnet/api/system.web.security.roles.getrolesforuser?view=netframework-4.8#System_Web_Security_Roles_GetRolesForUser

    If you have any question please let me know.

    Best regards,

    Sam 

    Thursday, October 31, 2019 8:46 AM