当前位置: 代码迷 >> Sql Server >> 传接参数到MS SQL里面出现一个特殊字符
  详细解决方案

传接参数到MS SQL里面出现一个特殊字符

热度:58   发布时间:2016-04-25 00:50:47.0
传递参数到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;
            }
        }
函数返回的字符是:?<NewDataSet><Gavin><NAME>Gavin</NAME></Gavin></NewDataSet>
  相关解决方案