Board index » delphi » Return a TDataSet

Return a TDataSet

hi,

I am using a sperate unit to get and write data to the database. What I need
is a method to return a TDataset ( to load data ).

If i give a SQL String as a parameter to the Method the return should be the
a TDataSet ( or the rows )

Please help me
Thanx

 

Re:Return a TDataSet


Use the next function:

function GetRows(const DBName, TableName: string): TDataset;
begin
  Result := TQuery.Create(Application);
  Result.DatabaseName := DBName;
  Result := 'SELECT * FROM ' + TableName;
  Result.Open;
end;

--
With best regards, Mike Shkolnik
E-Mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Fiqri <fi...@masters.lk> D??? ???Y??:3d3e27e8_1@dnews...

Quote
> hi,

> I am using a sperate unit to get and write data to the database. What I
need
> is a method to return a TDataset ( to load data ).

> If i give a SQL String as a parameter to the Method the return should be
the
> a TDataSet ( or the rows )

> Please help me
> Thanx

Re:Return a TDataSet


function GetQueryData(SQLStatement: String): TDataQuery;
begin
  Result := TQuery.Create(Application);
  with Result do
  begin
    SQL.Add(SQLStatement);
    Open;
end;

Make sure the caller frees the TQuery when it is done with it.

Quote
On Wed, 24 Jul 2002 10:11:20 +0600, "Fiqri" <fi...@masters.lk> wrote:
>hi,

>I am using a sperate unit to get and write data to the database. What I need
>is a method to return a TDataset ( to load data ).

>If i give a SQL String as a parameter to the Method the return should be the
>a TDataSet ( or the rows )

>Please help me
>Thanx

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Re:Return a TDataSet


Make that:

function GetQueryData(SQLStatement: String): TDataQuery;
begin
  Result := TQuery.Create(Application);
  with Result do
  begin
    SQL.Add(SQLStatement);
    DatabaseName := 'SomeDb';
    Open;
end;

On Wed, 24 Jul 2002 06:11:59 -0700, Bill Todd

Quote
<b...@notthis.dbginc.com> wrote:
>function GetQueryData(SQLStatement: String): TDataQuery;
>begin
>  Result := TQuery.Create(Application);
>  with Result do
>  begin
>    SQL.Add(SQLStatement);
>    Open;
>end;

>Make sure the caller frees the TQuery when it is done with it.

>On Wed, 24 Jul 2002 10:11:20 +0600, "Fiqri" <fi...@masters.lk> wrote:

>>hi,

>>I am using a sperate unit to get and write data to the database. What I need
>>is a method to return a TDataset ( to load data ).

>>If i give a SQL String as a parameter to the Method the return should be the
>>a TDataSet ( or the rows )

>>Please help me
>>Thanx

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Other Threads