How to dynamic add the field in TMSQuery

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

How to dynamic add the field in TMSQuery

Post by tcflam » Mon 25 Feb 2013 14:48

I have a problem in TMSQuery. How to add the field in TMSQuery? I don't want to pre-add the field in the TMSQuery. And my SQL is dynamic script. So I need to re-define the field in fielddef

AndreyZ

Re: How to dynamic add the field in TMSQuery

Post by AndreyZ » Tue 26 Feb 2013 11:42

You can use the following code:

Code: Select all

MSQuery1.SQL.Text := 'select * from tablename';
MSQuery1.FieldDefs.Add('fieldname', ftInteger);
MSQuery1.FieldDefs[0].CreateField(MSQuery1);
MSQuery1.Open;

tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: How to dynamic add the field in TMSQuery

Post by tcflam » Wed 27 Feb 2013 01:28

Sorry that I got the error message when using the following code. The error message is "E2034 Too Many actual parameters". Before I also use the following code for testing and got the same error. Any idea?

f.FieldName := msqry_dispfield.FieldByName('map_table_field').FieldName;
for i := low(FieldTypeStr) to high(FieldTypeStr) do
if msqry_dispfield.FieldByName('map_del_attrib').AsString = FieldTypeStr then
begin
msqry_result.Fields.Add(f, TFieldType(i));
msqry_result.FieldDefs[count].CreateField(msqry_result);
break;
end;

AndreyZ

Re: How to dynamic add the field in TMSQuery

Post by AndreyZ » Wed 27 Feb 2013 08:05

Please try creating a small sample to demonstrate the problem and send it to andreyz*devart*com . Also please specify the following:
- the exact version of SDAC. You can learn it from the About sheet of TMSConnection Editor;
- the exact version of your IDE.

Post Reply