I have the following Class which basically creates a list of categories (called commands, I know it’s weird)
Here is CommandDB.cs
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<Command> GetCommands()
{
List<Command> commandList = new List<Command>();
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;
}
}
}
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 List<CommandDB> commandList = new List<CommandDB.>GetCommands(); but I haven’t really had any luck figuring it out thru the msdn.
I think this is the syntax you are looking for.