//将DataTable转换成xml字符串: public string ConvertDataTableToXml(DataTable dt) { MemoryStream stream = null; XmlTextWriter writer = null; try { stream = new MemoryStream(); writer = new XmlTextWriter(stream, System.Text.Encoding.Unicode); dt.WriteXml(writer); int count = (int)stream.Length; byte[] arr = new byte[count]; stream.Seek(0, SeekOrigin.Begin); stream.Read(arr, 0, count); System.Text.Encoding ucode = System.Text.Encoding.Unicode; //若使用utf-8,遇中文会发生乱码 return ucode.GetString(arr).Trim(); } catch { return String.Empty; } }
将DataTable转换成xml字符串
时间: 2024-10-07 23:09:35