我无法将值从 Access 数据库中读取到列表中。值如下所示: 字段称为 EventDistance 值是 77 77 77 77 55 112 45 46
我的代码如下所示:
private void StartSchedule_Click(object sender, EventArgs e)
{
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\A2 Computing\C# Programming Project\TriHard.accdb";
string SelectQuery = "SELECT Time.AthleteID, Athlete.AthleteName,
Time.EventTime, Event.EventDistance
FROM Event INNER JOIN
(Athlete INNER JOIN [Time]
ON Athlete.[AthleteID] = Time[AthleteID])
ON Event.[EventID] = Time.[EventID];";
OleDbConnection Connection = new OleDbConnection(ConnectionString);
OleDbCommand Command = new OleDbCommand(SelectQuery, Connection);
Command.Connection.Open();
OleDbDataReader Reader = Command.ExecuteReader(CommandBehavior.CloseConnection);
PaceCalculator pace = new PaceCalculator();
List<PaceCalculator> Distancelist = new List<PaceCalculator>();
while (Reader.Read())
{
pace.Distance = (int)Reader["Event.EventDistance"];
Distancelist.Add(pace);
}
并且它抛出的 IndexOutOfRanceException 未针对 Event.EventDistance 进行处理。只有8个整数要读入,但我的数据必须有扩展空间。我怎样才能让它只读取整数而不引发索引错误?