locked
How to get all roles from Table1? RRS feed

  • Question

  • User38312806 posted

    I would like to get all roles from Table1 (i.e., 1roles, 2roles, 3roles, 4roles......), how to implement this function?

    public static string MyRoles()
        {
            if (MyUserRoles.IsRoles("1roles"))
            {
                return "1roles";
            }
            else if (MyUserRoles.IsRoles("2roles"))
            {
                return "2roles";
            }
            else if (MyUserRoles.IsRoles("3roles"))
            {
                return "3roles";
            }
            else if (MyUserRoles.IsRoles("4roles"))
            {
                return "4roles";
            }
            else
            {
                return null;
            }
        }
     
     
     
    Table1
    id    roles
    _________________
    1    1roles
    2    2roles
    3    3roles
    4    4roles

    Thursday, May 30, 2013 11:37 PM

All replies

  • User-1910946339 posted

    Why have you posted code for MyRoles?  What data type is Table1?  If it implements IEnumerable<T> then you can do

    var allRols = Table1.Select(t=>t.roles);

    Perhaps you could explan a little more about what you are trying to do?

    Friday, May 31, 2013 12:12 AM
  • User38312806 posted

    data table is Table1, data type is String

    Just I have tried the following codes,  but I loaded the GetRoles.MyGet().MyRoles().

    error: CS0023: Operator '.' cannot be applied to operand of type 'void'

    Please advise.

    DataTable dt = new DataTable();
            StringBuilder sb = new StringBuilder();
    
            sb.AppendLine("public static string MyRoles()");
            sb.AppendLine("{");
    
            if (dt != null)
            {
                sb.AppendLine("    if(MyUserRoles.IsRoles(\"" + dt .Rows [0][0].ToString () + "\"))");
                sb.AppendLine("    {");
                sb.AppendLine("        return \"" + dt .Rows [0][0] + "\";");
                sb.AppendLine("    }");
            }
    
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                sb.AppendLine("    else if(MyUserRoles.IsRoles(\"" + dt.Rows[i][0].ToString() + "\"))");
                sb.AppendLine("    {");
                sb.AppendLine("        return \"" + dt.Rows[i][0] + "\";");
                sb.AppendLine("    }");
            }
    
            sb.AppendLine("    else");
            sb.AppendLine("    {");
            sb.AppendLine("        return null;");
            sb.AppendLine("    }");
    
            sb.AppendLine("}");



    Friday, May 31, 2013 1:44 AM
  • User-1910946339 posted

    Sorry, I have no idea what you are talking about.  Can you start from the beginnning?  Are you trying to resolve a compilation error?  If so, show the code,show the full error message, tell us the line that the error message refers to.

     

     

    Friday, May 31, 2013 1:57 AM
  • User38312806 posted

    Can anyone suggest an easy way?

    Thanks in advance.

    Sunday, June 2, 2013 10:05 PM