Solved

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

Posted on 2006-06-30
6
188 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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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