title: c# sql database - how to reada all specific rows from table?
body: <p>I have a SQL Table "Roles" in DB. I want to find out if user have one or more Roles (Admin/User) and then do something with a value if user have 2 Roles at time.</p>
  
  <p>Problem: I cant get all Values from Database, I getting just a first one.</p>
  
  <p>can I do it with foreach loop? I dont have it here but i'm looking for solution. </p>
  
  <p>like: </p>
  
  <pre><code>            cmd = new SqlCommand();
              cmd.Connection = connection;
              cmd.CommandType = System.Data.CommandType.Text;
              cmd.CommandText = @"SELECT Role "
                                    + " FROM UsersRole "
                                    + " WHERE UserName = @UserName ";
              cmd.Parameters.Add(new SqlParameter("@UserName", username));
  
              reader = cmd.ExecuteReader();
  
              if (reader.HasRows)
              {
                  while (reader.Read())
                  {
                      if (reader["Role"] != DBNull.Value)
                      {
                          Role = Convert.ToString(reader["Role"]);
                          if(Role == UserRole.Admin.ToString())
                          {
                              IsAdmin = true;
                          }
                          if (Role == UserRole.User.ToString())
                          {
                              IsUser = true;
                          }
                      }
                      else
                      {
                          Role = "";
                      }
                  }
              }
              reader.Close();
  </code></pre>
  
  <p>IS it possible to access Table in DB with C# code or I can do it different?</p>
  
  <p>Thanks and take care,
  Ragims</p>