im trying to test if my list is collecting data from a database but when i try to get a message box to print a postcode from the list it gives me the exeption `System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'`
here are the methods which i have written and am using
private List<string> GetPostcodes(string table)
{
connect = new MySqlConnection(connectionString);
connect.Open();
string selectString = "select postcode from " + table;
MySqlCommand cmd = new MySqlCommand(selectString,connect);
reader = cmd.ExecuteReader();
while (reader.Read())
{
postcodes.Add(reader.GetOrdinal("postcode").ToString());
}
connect.Close();
return postcodes;
}
the list postcodes
is defined earlier in my code like this List<string> postcodes = new List<string>();
and here is how im trying to test the collection of the postcodes
private void Button_Click1(object sender, RoutedEventArgs e)
{
string test1 = postcodes[1];
MessageBox.Show(test1);
}