我目前正在处理一项任务,试图从 SQL Server 数据库中获取值并将它们存储在一个数组中。我的连接很好,但是我无法将返回的值放入数组中。
这是我所拥有的,自从我问这个问题以来已经改变了一点:
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();
}
得到错误
Bays.Add(temp)