如下一段文本:
     The company could supply the full range of steel flanges in accordance with ANSI, DIN, BS, UNI, ISO, JIS standard, and also could be manufactured by customers' special drawings. All the flanges made by forged system and size could be from: 1/8"-80".
  The company could supply Flat, Slip On, Welding Neck, Blind, Lap Joint, Socket, Threaded, Bund and Rings.
  The materials could be Carbon Steel: ASTM A105, Rst37.2 as per DIN 17100, C22.8 as per DIN 17200, BF42, BF48N and stainless Steel AISI304, 304L, 316, 316L and 1.4571.   Mill Test Certificate as per DIN 50049 3.1B   Detail Catalogues could be submitted by request.
      在使用insert语句插入SQL数据库时发生SQL语法错误,是文本中的特殊符号导致的,换成一些简单的字符就没有错了,可是在正常的工作中不可避免遇到这样的情况,大家是如何解决的?
在(ASP.NET ,C#,SQL SERVER2000)环境中。

解决方案 »

  1.   

    1,把一个单引号换成两个单引号
    2,用存储过程
    3,用参数    Public Function str(ByVal strParamer As String) As String
            Return "'" & Replace(strParamer, "'", "''") & "'"
        End Function
      

  2.   

    public static string Encode(String s)
    {
    String tempstr="";
    tempstr+=s.Replace("<","&lt;");
    tempstr=tempstr.Replace(">","&gt;");
    tempstr=tempstr.Replace(" ","&nbsp;");
    tempstr=tempstr.Replace("\'","\"");
    return tempstr;
    }
    public static string Decode(String s)
    {
    String tempstr="";
    tempstr+=s.Replace("&lt;","<");
    tempstr=tempstr.Replace("&gt;",">");
    tempstr=tempstr.Replace("&nbsp;"," ");
    tempstr=tempstr.Replace("\"","\'");
    return tempstr;
    }
      

  3.   

    大家的方法是可行,但是有没有更简单的方法呢?比如说如何使用System.Text.Encoding方法将字符串重新编码成 ascii或者其它什么的,纯粹以二进制或者十六进制写入,然后读取的时候再Decoding一下,不知道C#中有没有提供现成的方法?