Page 1 of 1

Migrating Data from nVarChar to VarBinary

Posted: Wed Mar 26, 2014 7:01 am
by TonyBlom
I have some old Rich View RTF data stored in nVarChar(MZX). Now I need to use VarBinary to work with SRV. I tried SQL Convert Function but it came out a mess.

Short of exporting all the data, converting then importing it, is there some way I can do the conversion ?

Thanks.

Additional Info

Posted: Wed Mar 26, 2014 11:12 am
by TonyBlom
I just like to add some more about the Data migration problem for me.

The old editor is just plain TRich View not SRV, and I used the DB aware version.

Thanks.

Posted: Thu Mar 27, 2014 7:04 am
by Sergey Tkachenko
I assume you added VarBinary field to the same table as contains nVarChar.

You can do the following.

Place dbsrv:TDBSRichViewEdit on the form, connect it to the source (nVarChar) field.
Let table is a data set connected to this table (and to TDBSRichViewEdit).
Let FieldName is a name of destination (VarBinary) field.

Code: Select all

var Stream: TStream; 

table.First;
while not table.EOF do begin
  table.Edit;
  Stream := table.CreateBlobStream(tbl.FieldByName(FieldName), bmWrite); 
  dbsrv.RichViewEdit.SaveRVFToStream(Stream, False); 
  Stream.Free; 
  table.Post;
  table.Next;
end;