title: Delphi - Updating Bar Chart on Date Inputs
body: <p>I'm trying to update my bar chart when dates are input into the text boxes and I am getting errors. I'm struggling to find a solution, so any help is appreciated. I would like it to update the dbGrid and chart, to show only the top 5 trainers for the dates input into the text boxes.</p>
  
  <pre><code>procedure TFTrainerChart.btnSubmitClick(Sender: TObject);
  var FromDate,ToDate:TDateTime;
  
    begin
  
  if AdoQuery1.Active then
      AdoQuery1.Close;
  
      FromDate:=strtoDateTime(txtFromDate.Text);
      ToDate:=strtoDateTime(txtToDate.Text);
  
       AdoQuery1.SQL.Add ( 'SELECT TOP 5 tblTrainers.Forename,');
        AdoQuery1.SQL.Add (' COUNT(tblTrainerBookings.TrainerID) AS Bookings');
        AdoQuery1.SQL.Add (' FROM tblTrainers,tblTrainerBookings') ;
        AdoQuery1.SQL.Add (' WHERE tblTrainers.TrainerID = tblTrainerBookings.TrainerID');
          AdoQuery1.SQL.Add ('AND tblTrainerBookings.DateOfBooking &gt;= :FromDate');
  
        AdoQuery1.SQL.Add ('AND tblTrainerBookings.DateOfBooking &lt;= :ToDate');
  
         AdoQuery1.SQL.Add ('GROUP BY tblTrainers.Forename');
         AdoQuery1.SQL.Add ('ORDER BY COUNT(tblTrainerBookings.TrainerID) DESC ');
  
         AdoQuery1.Parameters.ParamByName('ToDate').Value := ToDate;
         AdoQuery1.Parameters.ParamByName('FromDate').Value := FromDate;
  
         AdoQuery1.Open
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wU43Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wU43Q.png" alt="Order By syntax error"></a></p>
  
  <p><a href="https://i.stack.imgur.com/lsLFR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lsLFR.png" alt="My Two tables I&#39;m querying"></a></p>
  
  <pre><code>cs:='CREATE TABLE tblTrainers('+
    'TrainerID Number, '+
    'Forename TEXT(15), '+
    'Surname TEXT(20), '+
    'Address TEXT(30), '+
    'PostCode TEXT(9), '+
    'MobileNumber TEXT(11), '+
    'Email TEXT (40))';
    ADOCommand1.CommandText := cs;
    ADOCommand1.Execute;
  
   cs:='CREATE INDEX idxTrainer ON tblTrainers (TrainerID) WITH PRIMARY';
   ADOCommand1.CommandText := cs;
   ADOCommand1.Execute;
  
  cs:='CREATE TABLE tblTrainerBookings ('+
   'BookingID Number,'+
   'MemberID Number CONSTRAINT FKY_MemberID References tblMembers (MemberID),'+
   'TrainerID Number CONSTRAINT FKY_TrainerID References tblTrainers (TrainerID),'+
   'DateOfBooking Date,'+
    'TimeOfBooking Time)';
   ADOCommand1.CommandText :=cs;
   ADOCommand1.Execute;
  
   cs:='CREATE INDEX idxTrainerBooking ON tblTrainerBookings (BookingID) with PRIMARY';
   ADOCommand1.CommandText :=cs;
   ADOCommand1.Execute;
  </code></pre>