Solved

How too get a result from a SQL statmaent when asking a database

Posted on 2006-06-30
6
187 Views
Last Modified: 2010-04-16
How too does I get a result from a SQL statmaent when I'm asking a Pervasive database.
My code:
 sSQL := eSQL.Text;
  Query1.Close;
  Query1.SQL.Clear;
  iResultat := Query1.SQL.Add(select count(*) from jantest1 where maalernr=231;);
  if iResultat = 3 then
    showmessage('feil');
  Query1.ExecSQL;

iResultat only gets too be 0. But when i uses the same SQL statment direktly in the Pervasive database I get iResultat := 1, because there is a maalernr that is equal too 231.

P.S the result dont have too be an integer.

How too solve this?
0
Comment
Question by:liljen_80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Assisted Solution

by:dygj
dygj earned 30 total points
ID: 17016676
Query1.Close;
  Query1.SQL.Clear;
  Query1.SQL.Add('select count(*) from jantest1 where maalernr=231');
 query1.open
if query1.fields[0].asinteger=3 then showmessage('Erorr')

 Query1.ExecSQL executes a command, like update mytable..
query1.open return a result set.
0
 

Author Comment

by:liljen_80
ID: 17016746
Yes I got the result out then, but i got the error: "Query1: Cannot perform this operation on an open dataset."

How too get rid of this?
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17016830
The error message comes from other code not from the above one. So if you need this solved you should paste your code here.

Regards
0
Technology Partners: 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!

 
LVL 17

Accepted Solution

by:
mokule earned 20 total points
ID: 17016896
most probably
query1.close;
at the end of sequence will help
0
 
LVL 3

Expert Comment

by:dygj
ID: 17017734
procedure readmaalerno;
var
query1:tquery;
begin
try
query1:=tquery.create(self);
query1.databasename:='Mydatabase'
 Query1.SQL.Add('select count(*) from jantest1 where maalernr=231');
 query1.open
if query1.fields[0].asinteger=3 then showmessage('Erorr')

finally
freeandnil(query1);
end;
end;
0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 17017950
as has been stated your using the wrong method call

from TQuery help...Call ExecSQL to execute the SQL statement currently assigned to the SQL property. Use ExecSQL to execute queries that do not return a cursor to data (such as INSERT, UPDATE, DELETE, and CREATE TABLE).

Use Active or Open when you need a result set returned back...
0

Featured Post

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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