I have this function below, what I am trying to do, is connect to the database, run a query and put the results in a List and then return the list. This is what I came up so far,
public class AirportClass
{
private string connectionString;
private SqlConnection connection;
private SqlCommand command;
private Dictionary<string, List<string>> items;
public AirportClass()
{
connectionString = @"Server=server;database=database;uid=username;pwd=password;";
}
public Dictionary<string, List<string>> getListItems()
{
items = new Dictionary<string, List<string>>();
connection = new SqlConnection(connectionString);
command = new SqlCommand("SELECT * FROM Table");
command.Connection = connection;
connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
string data = dataReader[0].ToString();
items.Add(data);
}
connection.Close();
return items;
}
}
I have ran the debugger and I can see that I am getting a connection and data is getting returned, I am just have trouble putting the items into a list. I get error when I add the items.Add(data)
saying No overload for method 'Add' takes 1 arguments....can anyone help me out please?