Asp.Net sélectionnez dans Sql

Cela va être très simple, je le sais. J'ai vu tellement de façons différentes de l'utilisation de sql dans asp.net sans véritable standard. Ce que je veux savoir, c'est comment à proprement sélectionnez à partir d'une base de données sql dans asp.net et de récupérer des enregistrements multiples. Par exemple: sélectionnez tous les identifiants.

String sql = 
  "SELECT [UserId] FROM [UserProfiles] WHERE NOT [UserId] = 'CurrentUserId'";

string strCon = System.Web
                      .Configuration
                      .WebConfigurationManager
                      .ConnectionStrings["SocialSiteConnectionString"]
                      .ConnectionString;

SqlConnection conn = new SqlConnection(strCon);
SqlCommand comm = new SqlCommand(sql, conn);
conn.Open();

/*
 This is where I need to know how to retrieve the information from the
 above command(comm). I am looking for something similiar to php's
 mysql_result. I want to access the records kind of like an array or some
 other form of retrieving all the data.
 Also when the new SqlCommand is called...does that actual run the
 SELECT STATEMENT or is there another step. 
*/

conn.Close();
+1 pour le SqlCommand pour contrecarrer les injections.

OriginalL'auteur user84786 | 2009-03-31