How to get string Data from Tmemofield

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
garry
Posts: 7
Joined: Mon 02 Nov 2009 13:24
Location: India
Contact:

How to get string Data from Tmemofield

Post by garry » Wed 27 Oct 2010 17:49

I used TWideMemoField to save rtf text and now i have specific requirement to insert this rtf data in another table using Query

for this i used delphi code as Follows
[code]
// get data as string
rtfText := ThisQuery.FieldByName('RTF').AsWideString;
NewQuery.SQL.TEXT := 'Insert into NEWTABLE SET RTF= QuotedStr(rtfText );
NewQuery.Execute;
[/code]
when there are multiple lines in RTF text, i do have error in executing Query, after debugging NewQuery.SQL.TEXT i found that there are '#$D#$A' embedded in the Query text

Insert into NEWTABLE SET RTF=' {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}'#$D#$A'{\colortbl ;\red0\green0\blue255;}'#$D#$A'\viewkind4\uc1\pard\cf1\lang1040\b\fs16 MY TEXT!\cf0\b0\fs18\par'#$D#$A'}'#$D#$A#0''

is it correct method? if not please help me by suggesting some alternative method?(i want to do it through query)
Thanks

AndreyZ

Post by AndreyZ » Fri 29 Oct 2010 09:46

Hello,

You should use this code:

Code: Select all

  rtfText := ThisQuery.FieldByName('RTF').AsWideString;
  NewQuery.SQL.Text := 'INSERT INTO NEWTABLE(RTF) VALUES(:RTF)';
  NewQuery.ParamByName('RTF').AsWideString := rtfText;
  NewQuery.Execute;

garry
Posts: 7
Joined: Mon 02 Nov 2009 13:24
Location: India
Contact:

Post by garry » Fri 29 Oct 2010 10:59

Hi Thanks for your answer
Ok i agree with it but this task i want to perform for more than 500 records in multiple tables, and it may involve update and insert depending on some condition.
So i want to generate Queries programmatically and run them with help of TMSQuery/TMSScript to get optimum performance, but whole idea stuck with '#0D#0A' in Query text
Can you suggest some suitable idea to perform what i explained above or how i can i ignore or remove '#0D#0A'

AndreyZ

Post by AndreyZ » Mon 01 Nov 2010 12:44

The point is that the TStrings class cuts the last quote. To solve the problem you can use the following code:

Code: Select all

  rtfText := ThisQuery.FieldByName('RTF').AsWideString;
  NewQuery.SQL.Text := 'INSERT INTO NEWTABLE(RTF) VALUES(''' + rtfText;
  NewQuery.SQL.Text := NewQuery.SQL.Text + ''')';
  NewQuery.Execute;

Post Reply