Solved

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

Posted on 2006-06-30
6
181 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 211
Communication Between RC4 Delphi <-> PHP 3 100
Multiple image collision 13 69
Delphi and Access based Enumeration 9 47
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

23 Experts available now in Live!

Get 1:1 Help Now