Convert RTF to String via SQL?

Asked

Viewed 196 times

0

Good staff I have a small problem, I was asked to do it through SQL to convert a text made through a Richtextbox (VB 6) to normal string, but is that this Richtextbox also serves to by Chinese characters and this is where the problem exists.

I’ve been at it for 2 days, I couldn’t do it through SQL, I tried to make a DLL in C# for this and add to SQL and create a method in SQL to use the DLL, but I don’t have access to Class Richtextbox that is inside Winforms.dll (can’t 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 }

that I should give

夫 人 冯 夫 人 6346 个 红 的 桂 花

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

It will be possible to convert this via a DLL, without having access to class Richtextbox ?! That if I could access Class Richtextbox in DLL and add it to the SQL server would already be done, but unfortunately I cannot

Edit. After reading what was advised, I tried the Powershell solution (seen to have access to Richtextbox directly) but always gives me error.

The code I am 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

Where you always make this mistake:

The string is Missing the Terminator: '. + Categoryinfo : Parsererror: (:) [], Parentcontainserrorrecordex ception + Fullyqualifiederrorid : Terminatorexpectedatendofstring

But if Create a project in c# Winforms, go to fetch the info from DB and move to a Richtextbox the text appears as it should be without any problems.

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 do not understand the very broad, the problem is to want to pass an RTF to String normal in SQL, in which I passed the info as it should be, the example of RTF and what it returns if you put it in a Richtextbox, I asked only help for solutions to this

  • I recommend reading this article. It presents solution to this problem through SQL CLR(Common Language Runtime) and through Powershell, in addition to common solutions in C#.

  • Thank you, the DLL that speaks in the article (Richtextstripper) returns what I had already managed to 2 days through SQL ·òÈË·ë·òÈË6346¸öºìµÄ¹ð»¨ I’ll try the Powershell solution as you have access to Winforms might be able to do something of this later say something.

  • Okay, I’m trying to better understand this subject as well, but I shared the article because I think it could solve.

  • And thank you :D has the Powershell shape that gives me access to Winforms AKA The Richtextbox and I should get around

  • Yes, there should be a simpler solution to this type of situation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.