Using C#
how can I append to a List<string>
? I am wanting to run two seperate SQL Queries and store the results of both in my List<string>
. The first query returns
Bill and Joe
And the second query returns
James and Charles
But my Console.WriteLine()
only produces Bill
and Joe
What did I set-up improperly in my syntax for this to occur?
public static List<string> tempList = new List<string>();
static void Main(string[] args)
{
string qs = "Select Top 2 firstname from thistable";
//
GetFirstSetOfData(qs);
string bc = "Select Top 2 firstname from thattable";
//
GetFirstSetOfData(bc);
foreach (string tumble in tempList)
Console.WriteLine(tumble);
}
private static void GetFirstSetOfData(string query)
{
connection = new SqlConnection(ConnectionString);
{
cmd = new SqlCommand(queryString, connection);
connection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
tempList.Add(reader.GetValue(0).ToString());
reader.Close();
}
}