Board index » delphi » SELECT * ... - I NEED HELP

SELECT * ... - I NEED HELP

I'm able to insert my field-values into a table by

Query1.Sql.Clear;
Query1.Sql.Add( "INSERT INTO Test (col1, col2, col3)" );
Query1.Sql.Add( "VALUES (:a, :b, :c)" );
Query1.Params[ 0 ] := Value1;
Query1.Params[ 1 ] := Value2;
Query1.Params[ 2 ] := Value3;
Query1.ExecSql;

But how could I get the Values back from the Table Test into Variables
Value1, Value2 and Value3 with a Select-Statement and a Query?

 

Re:SELECT * ... - I NEED HELP


Quote
On Sat, 8 Jan 2000 16:21:48 +0100, "A Neef" <an...@t-online.de> wrote:
>I'm able to insert my field-values into a table by

>Query1.Sql.Clear;
>Query1.Sql.Add( "INSERT INTO Test (col1, col2, col3)" );
>Query1.Sql.Add( "VALUES (:a, :b, :c)" );
>Query1.Params[ 0 ] := Value1;
>Query1.Params[ 1 ] := Value2;
>Query1.Params[ 2 ] := Value3;
>Query1.ExecSql;

>But how could I get the Values back from the Table Test into Variables
>Value1, Value2 and Value3 with a Select-Statement and a Query?

The TQuery component does not support output parameters. To get your field
values, use a SELECT statement and, after activating the TQuery, access
individual fields with either the Fields property or the FieldByName
method. For example, the SQL statement might be:

  SELECT *
  FROM Test

Then, retrieving field values:

  with Query1 do begin
    Open;
    Var1 := FieldByName('Col1').Value;
    Var2 := FieldByName('Col2').Value;
    Var3 := FieldByName('Col3').Value;
  end;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Re:SELECT * ... - I NEED HELP


Thank you Steve,

you did a big step forward for me.

Greetings from Germany, Andreas.

Steve Koterski schrieb in Nachricht <38777e69.1855...@news.gte.net>...

Quote
>On Sat, 8 Jan 2000 16:21:48 +0100, "A Neef" <an...@t-online.de> wrote:

>>I'm able to insert my field-values into a table by

>>Query1.Sql.Clear;
>>Query1.Sql.Add( "INSERT INTO Test (col1, col2, col3)" );
>>Query1.Sql.Add( "VALUES (:a, :b, :c)" );
>>Query1.Params[ 0 ] := Value1;
>>Query1.Params[ 1 ] := Value2;
>>Query1.Params[ 2 ] := Value3;
>>Query1.ExecSql;

>>But how could I get the Values back from the Table Test into Variables
>>Value1, Value2 and Value3 with a Select-Statement and a Query?

>The TQuery component does not support output parameters. To get your field
>values, use a SELECT statement and, after activating the TQuery, access
>individual fields with either the Fields property or the FieldByName
>method. For example, the SQL statement might be:

>  SELECT *
>  FROM Test

>Then, retrieving field values:

>  with Query1 do begin
>    Open;
>    Var1 := FieldByName('Col1').Value;
>    Var2 := FieldByName('Col2').Value;
>    Var3 := FieldByName('Col3').Value;
>  end;

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>Steve Koterski              "Health nuts are going to feel stupid someday,
>Felton, CA                  lying in hospitals dying of nothing."
>                                                              -- Redd Foxx

Re:SELECT * ... - I NEED HELP


Select * from Test

Value1 := Query1.FieldByName('col1').AsString/AsInterger/AsDate
(Accordingly)

Regards
-Mani

Quote
A Neef <an...@t-online.de> wrote in message

news:947345573.451530@ba2.a-city.de...
Quote
> I'm able to insert my field-values into a table by

> Query1.Sql.Clear;
> Query1.Sql.Add( "INSERT INTO Test (col1, col2, col3)" );
> Query1.Sql.Add( "VALUES (:a, :b, :c)" );
> Query1.Params[ 0 ] := Value1;
> Query1.Params[ 1 ] := Value2;
> Query1.Params[ 2 ] := Value3;
> Query1.ExecSql;

> But how could I get the Values back from the Table Test into Variables
> Value1, Value2 and Value3 with a Select-Statement and a Query?

Re:SELECT * ... - I NEED HELP


Query1.Sql.Clear;
Query1.Sql.Add( 'select col1, col2, col3 from test' );
Query1.Open;
value1 := Query1.Fields[1].asinteger;

Instead of asinteger you can use proper variable type.

Mariusz Marcinkowski

Quote
>I'm able to insert my field-values into a table by

>Query1.Sql.Clear;
>Query1.Sql.Add( "INSERT INTO Test (col1, col2, col3)" );
>Query1.Sql.Add( "VALUES (:a, :b, :c)" );
>Query1.Params[ 0 ] := Value1;
>Query1.Params[ 1 ] := Value2;
>Query1.Params[ 2 ] := Value3;
>Query1.ExecSql;

>But how could I get the Values back from the Table Test into Variables
>Value1, Value2 and Value3 with a Select-Statement and a Query?

Other Threads