Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新数据表后,在SQL中删除换行符_C#_Sql Server_Newline - Fatal编程技术网

C# 更新数据表后,在SQL中删除换行符

C# 更新数据表后,在SQL中删除换行符,c#,sql-server,newline,C#,Sql Server,Newline,我有一个datatable,它通过去掉html进行修改。在html条带期间,如果遇到,或,它们将替换为System.Environment.NewLine。我正在将html strip进程的任何一个实例记录到一个文本文件中,并且日志中的格式看起来很好(所有CRLF都被保留)。但是,当对datatable调用update方法并将数据发送到数据库时,CRLF字符将全部消失 代码段: public static class HtmlStripper { static Regex _htmlRe

我有一个datatable,它通过去掉html进行修改。在html条带期间,如果遇到

  • ,它们将替换为
    System.Environment.NewLine
    。我正在将html strip进程的任何一个实例记录到一个文本文件中,并且日志中的格式看起来很好(所有CRLF都被保留)。但是,当对datatable调用update方法并将数据发送到数据库时,CRLF字符将全部消失

    代码段:

    public static class HtmlStripper
    {
        static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
        static Regex _liRegex = new Regex("<li>", RegexOptions.Compiled);
        static Regex _brRegex = new Regex("<(br)?(BR)?\\s?/?>\\s*", RegexOptions.Compiled);
        static Regex _pRegex = new Regex("</?[phPH].*?>\\s*", RegexOptions.Compiled);
    
        public static string StripTagsRegexCompiled(string source)
        {
            string noPorH = _pRegex.Replace(source, System.Environment.NewLine);
            string noBr = _brRegex.Replace(noPorH, System.Environment.NewLine);
            string noLi = _liRegex.Replace(noBr, System.Environment.NewLine + "t- ");
            return _htmlRegex.Replace(noLi, string.Empty);
        }
    
    }
    
    公共静态类HtmlStripper
    {
    静态Regex_htmlRegex=newregex(“,RegexOptions.Compiled);
    静态正则表达式=新正则表达式(“
  • ”,RegexOptions.Compiled); 静态正则表达式_brRegex=新正则表达式(“\\s*”,RegexOptions.Compiled); 静态正则表达式_pRegex=新正则表达式(“\\s*”,RegexOptions.Compiled); 公共静态字符串StripTagsRegexCompiled(字符串源) { 字符串noPorH=_pRegex.Replace(source、System.Environment.NewLine); 字符串noBr=\u brRegex.Replace(noPorH,System.Environment.NewLine); 字符串noLi=_liRegex.Replace(noBr,System.Environment.NewLine+“t-”); 返回_htmlRegex.Replace(noLi,string.Empty); } }
  • SSMS删除数据网格中的CRLF,但它们仍然存在于数据库中。您可以通过按
    CTRL-T
    来证明这一点,它将结果转换为文本,而不是在网格中。然后,您可以按CTRL-D键返回到网格中

    您可以使用以下方法对此进行测试:

    SELECT  'Not' + CHAR(10) + CHAR(13) + 'Together'
    
    首先,在网格中显示结果:

    (No Column name)
    Not  Together
    
    然后在文本结果中:

    SQL Server parse and compile time: 
       CPU time = 0 ms, elapsed time = 0 ms.
    
    -------------
    Not
    
    Together
    
    (1 row(s) affected)
    
    
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server parse and compile time: 
       CPU time = 0 ms, elapsed time = 0 ms.
    
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    

    一些代码剪贴可能有助于回答您的问题。您是否使用Sql Server Management Studio检查数据库中的数据?如果是这样,它会在显示时去掉换行符(但数据仍然正确)。我将数据从SSMS复制到Notepad++中,并且CRLF字符都消失了。@DanAndrews那么你是说如果我在应用程序中使用此数据,它将保留换行符?是的,它毕竟是SSMS。我从应用程序中查询数据库,并显示数据和CRLF字符。你每天都在学习。