Solved

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

Posted on 2006-06-30
6
183 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

786 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