日期:2014-05-17  浏览次数:20599 次

传递参数到MS SQL里面出现一个特殊字符
今天写了一个储存过程去存储DataTable转成XML字符
c#代码 DataTable转成XML的函数如下
public string DataTableToXml(DataTable dt)
        {
            try
            {
                if (dt == null)
                {
                    return "";
                }
                using (MemoryStream stream = new MemoryStream())
                {
                    using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.Unicode))
                    {

                        dt.WriteXml(writer);
                        int count = (int)stream.Length;
                        byte[] bytes = new byte[count];
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.Read(bytes, 0, count);
                        UnicodeEncoding encoding = new UnicodeEncoding();                        
                        string resultString=encoding.GetString(bytes).Trim();
                        return resultString;
                    }
                }
            }
            catch (Exception ex)
            {
                //调用日志函数
                throw ex;
          &nbs