Reputation: 1
real newbie question and I would appreciate any support you could offer. I am trying to output SQL results to a list. But when I return the list I get System.Collections.Generic.List`1[System.String] This my code, any ideas? Thank you in advance.
public static List<string> GetDTSXPackages()
{
List<String> packages = new List<String>();
using (SqlConnection connection = new SqlConnection(SQLConnectionString()))
{
string query = "SELECT PackageName FROM SharedServices.DTSXPackages";
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
packages.Add(reader["PackageName"].ToString());
}
}
connection.Close();
}
}
return packages;
}
static void Main(string[] args)
{
List<string> x = SQLAccessLayer.GetDTSXPackages();
foreach (var package in x)
{
Console.WriteLine(x);
}
}
Upvotes: 0
Views: 76
Reputation: 7766
It is not an error By doing a loop you can see all values
foreach(var i in Packages)
{
Console.WriteLine(i);
}
Upvotes: 1