how to create calc field runtime by msquery

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
minair2004
Posts: 5
Joined: Thu 26 Nov 2009 14:28
Location: iran
Contact:

how to create calc field runtime by msquery

Post by minair2004 » Wed 09 Dec 2009 08:08

hi
i need cod in create calc field runtime by msquery.

thnkx

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 09 Dec 2009 10:57

You can use the following code:

Code: Select all

var
  CalcField: TField;
begin
  CalcField := TIntegerField.Create(MSQuery);
  CalcField.Calculated := True;
  CalcField.FieldName := CalcFieldName;
  CalcField.DataSet := MSQuery;
end;

minair2004
Posts: 5
Joined: Thu 26 Nov 2009 14:28
Location: iran
Contact:

Post by minair2004 » Wed 09 Dec 2009 13:10

thnx

i use this code. but msquery only show 1 fields. don't show another fields and error in exit form.

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 09 Dec 2009 15:31

To create the fields of your SQL query in run-time, use the following code:

Code: Select all

  MSQuery.FieldDefs.Update;
  for i := 0 to MSQuery.FieldDefList.Count - 1 do
    with MSQuery.FieldDefList[i] do
      if (DataType  ftUnknown) and not (DataType in ObjectFieldTypes) then
        CreateField(MSQuery, nil, MSQuery.FieldDefList.Strings[i]);
After that add calculated field and then open the query.

Post Reply