Board index » delphi » Query problems

Query problems

Hello,

I have the following questions about the DB possibilities in Delphi:

-  I want to perform a query like this: Select * from DATA where User =
"MyUserID". I have performed this query in Access where it works fine, but
when I use the Query component, I get the message: Too few parameter.
Expected 1.. What's this??

- How can I count the number of results from a query? I would like to add a
counter, something like 'This is record 1 of 10'. Is this standard
available?

- I would like to perform a query that gives strings as a result that begin
with another specified string. So when I type '0' I get all results (from a
certain column) that begin with '0'. As the typing advances, I get fewer
results.

Many thanks for your help. I realise that not all questions are on topic,
but it's worth trying I hope.

Darius Blaszijk

 

Re:Query problems


"Darius Blaszijk" <DBlasz...@ZonNet.nl> skrev i melding
news:fDJM5.30049$tL4.377565@zonnet-reader-1...

Quote
> Hello,

> I have the following questions about the DB possibilities in Delphi:

> -  I want to perform a query like this: Select * from DATA where User
=
> "MyUserID". I have performed this query in Access where it works fine,
but
> when I use the Query component, I get the message: Too few parameter.
> Expected 1.. What's this??

I believe the following happens:

No parameters are identified by the TQuery object in your SQL statement.
The syntax that TQuery would recognize would be:

  ... where User = :MyUserID

Now, I'm quite sure this is the problem: The SQL parser of TQuery
doesn't recognize any parameters, while Access db-engine does, and
expects parameter values passed.
I don't know how to fix it, togh:

a) Rewrite the Query to specify parameters with a :MyUserID  ??
b) Add Parameter definitions manually (or by code), because the built-in
SQL parser don't recognize them ??

(too much hazzle for me to get an Access database up & running to test
it...)

Quote

> - How can I count the number of results from a query? I would like to
add a
> counter, something like 'This is record 1 of 10'. Is this standard
> available?

You can ask for

  Query.RowCount;

..but beware this may take a while...

Quote
> - I would like to perform a query that gives strings as a result that
begin
> with another specified string. So when I type '0' I get all results
(from a
> certain column) that begin with '0'. As the typing advances, I get
fewer
> results.

The *really* elegant solution to this is putting the search query in a
separate thread, so that you don't have to wait for the query to finish
until the next character is shown.

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Query problems


Darius Blaszijk <DBlasz...@ZonNet.nl> D???
???Y??:fDJM5.30049$tL4.377565@zonnet-reader-1...

Quote
> Hello,

> I have the following questions about the DB possibilities in Delphi:

> -  I want to perform a query like this: Select * from DATA where User =
> "MyUserID". I have performed this query in Access where it works fine, but
> when I use the Query component, I get the message: Too few parameter.
> Expected 1.. What's this??

In the TQuery component you should use parameter like ":MyUserID".

Quote
> - How can I count the number of results from a query? I would like to add
a
> counter, something like 'This is record 1 of 10'. Is this standard
> available?

There is a SQL statement count(). Example:
select count(*) from data;

Quote
> - I would like to perform a query that gives strings as a result that
begin
> with another specified string. So when I type '0' I get all results (from
a
> certain column) that begin with '0'. As the typing advances, I get fewer
> results.

select * from data where stringcolumn like 0%
Quote

> Many thanks for your help. I realise that not all questions are on topic,
> but it's worth trying I hope.

> Darius Blaszijk

Re:Query problems


Quote
"Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message

news:fDJM5.30049$tL4.377565@zonnet-reader-1...

Quote
> Hello,

> I have the following questions about the DB possibilities in Delphi:

> -  I want to perform a query like this: Select * from DATA where User =
> "MyUserID". I have performed this query in Access where it works fine, but
> when I use the Query component, I get the message: Too few parameter.
> Expected 1.. What's this??

> - How can I count the number of results from a query? I would like to add
a
> counter, something like 'This is record 1 of 10'. Is this standard
> available?

> - I would like to perform a query that gives strings as a result that
begin
> with another specified string. So when I type '0' I get all results (from
a
> certain column) that begin with '0'. As the typing advances, I get fewer
> results.

> Many thanks for your help. I realise that not all questions are on topic,
> but it's worth trying I hope.

> Darius Blaszijk

1)  assuming an embedded query

MyQuery.SQL.clear;
MyQuery.SQL.Add( 'select * from <tableName>  where  <fieldName  =
 <value> );
MyQuery.Open;
{
while not MyQuery.EOF do  begin
aRecordCounter := aRecordCounter + 1;

{ here you can assign  the resulting record to a variable  like this

MyStringVariable :=  MyQuery.FieldByname('<fieldName>').asString;
MyIntegerVariable := MyQuery.FieldByname('<fieldName>').asInteger;
MyFloatVariable := MyQuery.FieldByname('<fieldName>').asFloat;

or you can put each record into a stringlist for later processing .
.
.
.
.
.
MyQuery.next;
end;
MyQuery.close;

2)    the query object has a methods called  "recordCount"  &  "recNo" they should be of assistance

Other Threads