1

I have an Access Database reading in a list of Athletes, their times and the distance of the events.

I want to calculate the pace of each athlete, and produce a new database with the Athlete ID (Primary Key), Athlete Name and their Pace.

The pace will be the time divided by the distance.

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 Query].Time, [Time Query].EventDistance, [Time Query].AthleteID FROM [Time Query];";
    OleDbConnection Connection = new OleDbConnection(ConnectionString);
    OleDbCommand Command = new OleDbCommand(SelectQuery, Connection);
    Command.Connection.Open();
    OleDbDataReader Reader = Command.ExecuteReader(CommandBehavior.CloseConnection);

    List<PaceCalculator> list = new List<PaceCalculator>();
    while (Reader.Read())
    {
        PaceCalculator pace = new PaceCalculator();
        pace.Distance = (int)Reader["EventDistance"];
        pace.EventTime = 

        pace.Pace = pace.EventTime / pace.Distance;
    }
}

So I am not entirely sure if I am reading in the right thing, and the code is obviously incomplete, but you can see what I am trying to achieve from my last line there.

I have a separate class where my variables are coming from:

public class PaceCalculator
{
    public TimeSpan EventTime;
    public Int32 EventTimeInt {get; set; }
    public int Distance {get; set;}
    public int Pace {get; set;}
}

But again I am not sure I am using the right variable types for the job. The times are in HH:MM:SS.

Am I doing this the best way? and if not, what is the best way?

3
  • Have you ruled out using a field expression in an Access query to calculate pace?
    – HansUp
    Feb 2, 2015 at 19:21
  • 1
    First you need to nail down the terminology. You want to "produce a new database"? I doubt it. Perhaps you want to produce a new table, but in fact I suspect that you want to produce a query (often called a view in other databases) to display the athlete's ID, Name, and Pace. If so, please edit your question to clarify what you are trying to achieve (besides getting your #%^#$! homework assignment done :). As @HansUp says, it could be as simple as SELECT ... [Time]/[EventDistance] AS Pace FROM .... Feb 2, 2015 at 20:33
  • Wow, I hadn't realized you could divide in a query. I wanted the Pace to Correspond with the Athlete's name and ID, and I would like it in a separate database so the Event Organizer can just see the database of the Athletes and their Pace. Feb 3, 2015 at 19:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.