Solved

Error when Appending SQL to ADOQuery

Posted on 2004-03-24
4
640 Views
Last Modified: 2010-04-06
I am Using Delphi 6 Enterprise under Windows 2000, and am using ADO to connect to an ACCESS 2000 Database.

I basically use ADOQueries to connect to the Access Database and generally have NO problems, except, when I use code similar to the following I get the following error: Project XXXXX.exe has raised exception class EAccessViolation with message 'Access violation at address 1B041851 in module 'msjet40.dll'........ etc...

-----------------------------------------------------------------------
if qwkTable2.Active then dmMain.qwkTable2.Close;

  qwkTable2.SQL.Clear;
  qwkTable2.SQL.Append('SELECT Sum(mQuoteDetails.TotalCost) AS SumOfTotalCost, Sum(mQuoteDetails.TaxAmount) AS SumOfTaxAmount');
  qwkTable2.SQL.Append('FROM mQuoteDetails');
  qwkTable2.SQL.Append('GROUP BY mQuoteDetails.JobID, mQuoteDetails.QuoteID');
  qwkTable2.SQL.Append('HAVING ((mQuoteDetails.JobID='+IntToStr(iJobID)+') AND (mQuoteDetails.QuoteID='+IntToStr(iQuoteID)+'))');
  qwkTable2.Open;
-----------------------------------------------------------------------

Basically the qwkTable2 is a ADOQuery with NO SQL code, which I use as a WORK TABLE, that is SQL can change depending on the function. The error occurs after the first APPEND statement (I have tried OTHER statement types, even simple SELECT statements). I thought that the ADOQuery may be in use, so I added the first line, but still no luck.

If I hard code the above Query into the ADOQuery component it works OK, but when I use the above method I get errors.

Note: I have done this on many occasions with SQL Server, with no problems.


Any help would be greatly appreciated

Thanks
PE
0
Comment
Question by:pjelias
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10666553
Use SQL.Add instead of Append
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 125 total points
ID: 10666733
try this:

  with dmMain do
  begin
    qwkTable2.Active := False;
    qwkTable2.SQL.Clear;
    T := ''
       + ' SELECT Sum(mQuoteDetails.TotalCost) AS SumOfTotalCost, Sum(mQuoteDetails.TaxAmount) AS SumOfTaxAmount'
       + ' FROM mQuoteDetails'
       + ' GROUP BY mQuoteDetails.JobID, mQuoteDetails.QuoteID'
       + ' HAVING ((mQuoteDetails.JobID='
       + QuotedStr(IntToStr(iJobID))
       + ') AND (mQuoteDetails.QuoteID='
       + QuotedStr(IntToStr(iQuoteID))
       +'))'
       + '';
    qwkTable2.SQL.Text := T;
    qwkTable2.Open;
  end;
0
 

Author Comment

by:pjelias
ID: 10666830
esoftbg,

thanks for the quick response and solution

Question though, why does your code work and not mine ?, yet my code works when using SQL SERVER (I am fairly new to using ACCESS)


Regards
PE
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10666911
I think there is 3 reasons:
1. it must to be a space before: FROM, 'GROUP BY and HAVING
2. it must to be quoted the values of IntToStr(iJobID) and IntToStr(iQuoteID)
3. when I place a breakpoint on the line:     qwkTable2.SQL.Text := T;
applikation stops there an I see the content of T

emil
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Base1 Encode/Decode 3 85
How to load 2 images in same column in Delphi 2 67
Delphi android app hide keyboard 3 40
Get weeknumber and year from date 4 25
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

713 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