Page 1 of 1
How to dynamic add the field in TMSQuery
Posted: Mon 25 Feb 2013 14:48
by tcflam
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
Re: How to dynamic add the field in TMSQuery
Posted: Tue 26 Feb 2013 11:42
by AndreyZ
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;
Re: How to dynamic add the field in TMSQuery
Posted: Wed 27 Feb 2013 01:28
by tcflam
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;
Re: How to dynamic add the field in TMSQuery
Posted: Wed 27 Feb 2013 08:05
by AndreyZ
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.