Solved

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

Posted on 2006-06-30
6
179 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

12 Experts available now in Live!

Get 1:1 Help Now