Hi
I try to create an update statement during runtime using TMyQuery:
Qry.SQLUpdate.Add('UPDATE persoon SET FIELD1=');
Qry.SQLUpdate.Add('''');
Qry.SQLUpdate.Add(DataSet.FieldByName('FIELD1').AsString);
Qry.SQLUpdate.Add('"');
Qry.SQLUpdate.Add(', FIELD2="');
Qry.SQLUpdate.Add('''');
Qry.SQLUpdate.Add(DataSet.FieldByName('FIELD2').AsString);
Qry.SQLUpdate.Add('"');
etc.
I can use Add() or Append() but in both cases each added string comes on the next line (CR/LF). This means that I get an error after POST.
Can someone tell me how I should concatenate al these strings into one string without CR/LF
best regards,
Hans
How to create update statement
This should do the job:
But as it's a SQLUpdate, this is more correct and easier:
But you've forgot important part of query, the WHERE condition, right now it would update all records.
Regards
Code: Select all
Qry.SQLUpdate.Clear;
Qry.SQLUpdate.Add( 'UPDATE persoon SET FIELD1 = '+QuotedStr(DataSet.FieldByName('FIELD1').AsString)+' , FIELD2 = '+QuotedStr(DataSet.FieldByName('FIELD1').AsString) );
Code: Select all
Qry.SQLUpdate.Clear;
Qry.SQLUpdate.Add( 'UPDATE persoon SET FIELD1 = :FIELD1, FIELD2 = FIELD2' );
Regards