title: accessing class that creates list from database
body: <p>I have the following Class which basically creates a list of categories (called commands, I know it's weird)</p>
  
  <p>Here is CommandDB.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Data;
  using System.Data.Common;
  using System.Data.Sql;
  using System.Data.SqlClient;
  
  namespace TM_non_deploy
  {
      public partial class CommandDB
      {
          private static string connectionString = "blah";
  
          public static List&lt;Command&gt; GetCommands()
          {
              List&lt;Command&gt; commandList = new List&lt;Command&gt;();
  
              DbConnection connection = new SqlConnection();
              SqlCommand cmd = (SqlCommand)connection.CreateCommand();
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.CommandText = "sp_tm_commands";
  
              connection.ConnectionString = GetConnectionString();
              connection.Open();
  
              SqlDataReader reader = null;
              reader = cmd.ExecuteReader();
  
              Command command;
  
              while (reader.Read())
              {
                  command = new Command();
  
                  command.ID = reader.GetOrdinal("id");
                  command.Name = reader["name"].ToString();
  
                  commandList.Add(command);
              }
  
              reader.Close();
              connection.Close();
  
              return commandList;
  
          }
  
          private static string GetConnectionString()
          {
              return connectionString;
          }
  
      }
  }
  </code></pre>
  
  <p>my question is hopefully pretty simple, how do I, in my main page, access this list so that it calls the function and returns all the commands so I can iterate thru them? I thought it might be something like <code>List&lt;CommandDB&gt; commandList = new List&lt;CommandDB.&gt;GetCommands();</code> but I haven't really had any luck figuring it out thru the msdn. </p>