Solved

problem with query

Posted on 2004-10-29
237 Views
Last Modified: 2010-04-05
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?
0
Question by:selas
    5 Comments
     
    LVL 27

    Expert Comment

    by:kretzschmar
    does your dbgrid have persistent columns?
    0
     

    Author Comment

    by:selas
    If look in dbgrid column editor there is no columns...
    0
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 17

    Expert Comment

    by:geobul
    I've answered this question.
    0
     
    LVL 27

    Expert Comment

    by:kretzschmar
    yep, geo answered this q and deserves the points
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now