Convert RTF to String through SQL?

0

Well, I have a small problem, I was asked to convert a text made from a RichTextBox (VB 6) to a normal string, but this RichTextBox also works for Chinese characters and is here that the problem exists.

I'm already in 2 days, I could not do this through SQL, I tried to make a C # DLL for this and add it to SQL and create a SQL method to use the DLL, but I do not have access to the RichTextBox Class that you can find it inside WinForms.dll (not to add to SQL).

As an example I have this RTF:

{\rtf1\ansi\ansicpg1252\deff0\deflang2070{\fonttbl{\f0\fmodern\fprq6\fcharset134 SimSun;}{\f1\fnil\fcharset0 MS Sans Serif;}}  \viewkind4\uc1\pard\lang2052\f0\fs17\'b7\'f2\'c8\'cb\'b7\'eb\'b7\'f2\'c8\'cb6346\'b8\'f6\'ba\'ec\'b5\'c4\'b9\'f0\'bb\'a8\lang2070\f1   \par }

which you should give

  

夫人 冯 夫人 6346 个 红 的 桂花

I have already advised you to have a field in the SQL table one for the RTF and another for the string, not ideal but would be a solution.

Is it possible to convert this through a DLL without having access to the RichTextBox class?! If you can get access to the RichTextBox Class in DLL and it can be added to the SQL server already it would be done, but unfortunately I can not

Edit. After reading what was advised, I tried the PowerShell solution (since I have access to the RichTextBox directly) but it always gives me error.

The code I'm testing in SQL:

DECLARE 
@StringRTF VARCHAR(MAX),
@Posh VARCHAR(8000)


SET @StringRTF = (select traduçao from artigos where Cod_Art='01010066')
SET @Posh = 'powershell.exe -ExecutionPolicy ByPass -Command "Add-Type -AssemblyName System.Windows.Forms; $Rtb = New-Object -TypeName System.Windows.Forms.RichTextBox; $stringRTF = ''' + @StringRTF + '''; $Rtb.Rtf = $stringRTF; $Retorno = $Rtb.Text; Write-Host($Retorno);"'

EXEC master.dbo.xp_cmdshell @Posh

In which I always get this error:

  

The string is missing the terminator: '.       + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordEx      ception       + FullyQualifiedErrorId: TerminatorExpectedAtEndOfString

But if at Create a project in C # WinForms, go fetch the info from the DB and move to a RichTextBox the text appears as it should be no problems at all.

string tempString = String.Empty;
using (var con = new SqlConnection(SQLString))
{
    con.Open();
    {
        using (var cmd = con.CreateCommand())
        {
            cmd.CommandText = "select traduçao as tradu from artigos where Cod_Art='01010066'";
            using (var dr = cmd.ExecuteReader())
            {
                dr.Read();
                tempString = dr["tradu"].ToString();
            }
        }
    }
}
this.RichTextBoxTest.Rtf = tempString;
string testString = this.RichTextBoxTest.Text;

BtW I do not understand the very wide, the problem is to want to pass an RTF to normal String in SQL, in which I passed the info as it should, the RTF example and what it returns if the in a RichTextBox, I just asked help for solutions to this

    
asked by anonymous 07.12.2018 / 11:33

0 answers