I am working on an assignment at the moment, trying to get values from a SQL Server database and storing them in an array. My connection is fine, but I am having trouble putting the returned values into an array.
Here is what I've got, have changed it a bit since I asked the question:
public int Bay;
int temp;
[DataContract]
public Garage()
{
List<Garage> Bays = new List<Garage>();
SqlConnection connection = new SqlConnection("Data Source=fastapps04.qut.edu.au;Initial Catalog=*******;User ID=******;Password=******");
connection.Open();
SqlCommand command = new SqlCommand("SELECT Bay FROM Garage", connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
temp = reader.GetOrdinal("Bay");
Bays.Add(temp);
}
Bays.ToArray();
reader.Close();
connection.Close();
}
Getting the error at
Bays.Add(temp)