๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1479

Re: Storing Unicode text to ntext field of MS SQL 2000 Server

#1479
From: James Peterson
Date: Thu, 01 Jul 2004 15:11
79 lines
3031 bytes
try something like this

 TStream *Blob
=ADOQuery1->CreateBlobStream(ADOQuery1->FieldByName("nTextField"), bmWrite);
    try {
        RichEdit7->Lines->SaveToStream(Blob);
    }
    __finally {
        delete Blob;
    }

  This works for me reading from a RichEdit. Saves all formating of
charactors and everything.



"Michael Kuhl" <no_emails@gmx.de> wrote in message
news:40e427af$1@newsgroups.borland.com...
> Hello,
>
> I'm trying to save an unicode text (memo) to a ntext field. I tried
several
> ways to store the text (like you see below) but non of them worked (I'm
only
> getting questions marks when I read out the data). My nvarchar field is
> working fine.
>
> I'm using Delphi 5 and the Tnt Components.
>
> procedure TForm1.Button1Click(Sender: TObject);
> var  stream: TStringStream ;
>      file://bstream: TADOBlobStream;
> begin
>   stream := TStringStream.Create('');
>   try
>     ADOConnection1.BeginTrans;
>
>     ADOQuery1.Append;
>     ADOQuery1.FieldByName('id').AsInteger       := StrToInt(Edit1.Text);
>     ADOQuery1.FieldByName('Text').AsVariant     := TntEdit1.Text; //
> nvarchar
>     file://ADOQuery1.FieldByName('xml').AsVariant := '';  // ntext
>
>     stream.size := 0;  // Inhalt l๏ฟฝschen
>     TntMemo2.Lines.SaveToStream(stream, false);
>     stream.Position := 0;
>     // TBlobField(ADOQuery1.FieldByName('xml')).LoadFromStream(stream);
>
>     TWideStringField(ADOQuery1.FieldByName('xml')).AsVariant :=
> TntMemo2.Lines.Text;
>     file://TWideStringField(ADOQuery1.FieldByName('xml')).AsString :=
> TntMemo2.Lines.Text;
>
>     // bstream :=
> TADOBlobStream(ADOQuery1.CreateBlobStream(ADOQuery1.FieldByName('xml'),
> bmReadWrite));
>     file://bstream.CopyFrom(stream, 0);
>
>     ADOQuery1.Post;
>
>     // ADOQuery1.Edit;
>     // ADOQuery1.Recordset.Fields['xml'].Value := TntMemo2.Lines.Text;
>     // ADOQuery1.Post;
>
>     ADOConnection1.CommitTrans;
>     file://bstream.Destroy;
>   except
>     ADOConnection1.RollbackTrans;
>   end;
>   stream.free;
> end;
>
> Any suggestions?
>
> Best regards
>
> Michael
>
>
Technical Details
Message-ID: <40e4291a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40e427af$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,456515383264a299
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII
From: "James Peterson" <jpeterson@romanmealmilling.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40e427af$1@newsgroups.borland.com>
Subject: Re: Storing Unicode text to ntext field of MS SQL 2000 Server
Date: Thu, 1 Jul 2004 10:11:06 -0500
Lines: 81
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 64.21.236.129
Message-ID: <40e4291a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1088694554 64.21.236.129 (1 Jul 2004 08:09:14 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail