problem with query

on form i have two buttons, dbgrid and dbchart

on button press:

procedure TForm1.Button1Click(Sender: TObject);
begin
Series1.YValues.ValueSource := '';
AdoQuery1.Fields.Clear;
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('select krupje, laikas, sum(viso) from chipsai where laikas > '+QuotedStr(DatetoStr(DateTimePicker1.Date - 1))+' group by krupje order by laikas');
AdoQuery1.Open;
AdoQuery1.FieldDefList.Update;
Series1.YValues.ValueSource := 'sum(viso)';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Series1.YValues.ValueSource := '';
AdoQuery1.Fields.Clear;
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('select krupje, laikas, sum(skirtumas) from chipsai where laikas > '+QuotedStr(DatetoStr(DateTimePicker1.Date - 1))+' group by krupje order by laikas');
AdoQuery1.Open;
AdoQuery1.FieldDefList.Update;
Series1.YValues.ValueSource := 'sum(skirtumas)';
end;

if i press one button all works fine, but if i press after any button i got error:
AdoQuery1: Field '' not found.
if there is no dbgrid all works fine too
How to fix it?
selasAsked:
Who is Participating?
 
geobulConnect With a Mentor Commented:
You don't close the query:

procedure TForm1.Button1Click(Sender: TObject);
begin
Series1.YValues.ValueSource := '';
AdoQuery1.Close; // <-- this line
AdoQuery1.Fields.Clear;
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('select krupje, laikas, sum(viso) from chipsai where laikas > '+QuotedStr(DatetoStr(DateTimePicker1.Date - 1))+' group by krupje order by laikas');
AdoQuery1.Open;
AdoQuery1.FieldDefList.Update;
Series1.YValues.ValueSource := 'sum(viso)';
end;

and the same in the other button event.

Regards, Geo
0
 
kretzschmarCommented:
does your dbgrid have persistent columns?
0
 
selasAuthor Commented:
If look in dbgrid column editor there is no columns...
0
 
geobulCommented:
I've answered this question.
0
 
kretzschmarCommented:
yep, geo answered this q and deserves the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.