C# inserts incomplete text into the database

Asked

Viewed 39 times

0

Hello, I have an application in . Net C# that updates/inserts a text in HTML format in the Mysql database. In my table in the database I have a field of type Longblob that will store this text.

But for some reason when a text of any size is inserted into the database it is still incomplete.

This is the method responsible for saving the text in the database, in this method the file parameter is coming with the full text

        public void AtualizaArquivoBlob(string arquivo, int codigo, bool isInserir)
        {
            string query;

            if (isInserir)
                query = "insert arquivo_blob (html_arb,codarq_arb) values (?arquivo, ?codigo)";
            else
                query = "update arquivo_blob set html_arb = ?arquivo where codarq_arb = ?codigo";

            using (var cmd = CustomCommant(query, Conexao_Model.GetInstace().Connection))
            {

                cmd.Parameters.Add(new MySqlParameter("?arquivo", MySqlDbType.LongBlob) { Value = arquivo });
                cmd.Parameters.Add(new MySqlParameter("?codigo", MySqlDbType.Int32) { Value = codigo });

                cmd.ExecuteNonQuery();

            }
        }

Something I realized in my analysis with an example text, is that file. Length is 723, but when I copy the full text contained in the file variable and paste it into Notepad++ for example its Length is 740. After the text saved in the database if I save this content from the database in Notepad++ its Length is 723 and the text is incomplete.

This is the full text:

\r\n<p style="text-indent:0pt;margin-top:0pt;margin-bottom:0pt;"><span style="color:#000000;font-weight:bold;">SAIBAM</span><span style="color:#000000;"> quantos esta pública escritura de </span><span style="color:#000000;font-weight:bold;">DECLARAÇÃO</span><span style="color:#000000;"> virem que, sendo æData_lav1&gt; , neste Distrito de Itaió, 2º do município e comarca de Itaiópolis, Estado de Santa Catarina, neste Ofício de Notas, sito às margens da Rodovia SC 477, s/n, §1compareceu§ como </span><span style="color:#000000;font-weight:bold;">declarantes</span><span style="color:#000000;">:- ¿DADOS_DOS_OUTORGANTES_E_RECIPROCAMENTE_OUTORGADOS&gt; . E, assim, §1pelo§ §1declarante§ me foi dito o seguinte:-</span></p>

This is the text saved in the database:

\r\n<p style="text-indent:0pt;margin-top:0pt;margin-bottom:0pt;"><span style="color:#000000;font-weight:bold;">SAIBAM</span><span style="color:#000000;"> quantos esta pública escritura de </span><span style="color:#000000;font-weight:bold;">DECLARAÇÃO</span><span style="color:#000000;"> virem que, sendo æData_lav1&gt; , neste Distrito de Itaió, 2º do município e comarca de Itaiópolis, Estado de Santa Catarina, neste Ofício de Notas, sito às margens da Rodovia SC 477, s/n, §1compareceu§ como </span><span style="color:#000000;font-weight:bold;">declarantes</span><span style="color:#000000;">:- ¿DADOS_DOS_OUTORGANTES_E_RECIPROCAMENTE_OUTORGADOS&gt; . E, assim, §1pelo§ §1declarante§ me foi dito o seguin

If anyone has any idea what might be going on I’d be very grateful.

  • 1

    is not removing the escape characters, for example \r\n?

  • it should insert a string run, regardless of the characters.

  • 2

    if it should be something else, but the fact is that it is not, and for a simple reason, you are using incorrect data type. Fields of the type BLOBare for storing binary data and not text, should use a field TEXT for example, or convert the string to binary

  • @Ricardopunctual really is this, had used Blob by the fact that my field in the bank is Blob. I will pay attention next time, thank you very much!

  • 1

    good, but in the end it’s simple if you don’t want to change the type, just use the method System.Text.Encoding.UTF8.GetBytes to convert the string to bytes, and otherwise at read time and will work

No answers

Browser other questions tagged

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