将DataSet对象转换为Xml字符串变量... [英] Convert DataSet object to Xml string variable...

查看:74
本文介绍了将DataSet对象转换为Xml字符串变量...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试寻找一种将数据集对象转换为xml并将其分配的方法
到一个字符串变量而不保存到文件中.显然我不想
通过写入磁盘来减慢该过程,但是我发现的所有方法都如此
far(dataset.writexml)写入文件.我认为有一种方法可以使用
流对象,但我什么都没想.我该如何完成
没有写入磁盘?

谢谢.

Hello,

I''m trying to find a way to convert a dataset object to xml and assign that
to a string variable without saving to a file. Obviously I don''t want to
slow down the process by writing to disk, but all the methods I''ve found so
far (dataset.writexml) write to a file. I think there''s a way to use a
stream object, but I haven''t come up with anything. How can I get this done
without writing to disk?

Thanks.

推荐答案

如何使用 ^ ]?

http://geekswithblogs. net/mnf/archive/2008/08/14/convert--dataset--and-datatable-to-xml-string-helper.aspx [
How about using StringWriter[^]?

http://geekswithblogs.net/mnf/archive/2008/08/14/convert--dataset--and-datatable-to-xml-string-helper.aspx[^]

public static string ToStringAsXml(DataSet ds)
{
    StringWriter sw = new StringWriter();
    ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);
    string s = sw.ToString();
    return s;
}



糟糕,刚注意到VB.Net标签



Oops, just noticed the VB.Net tag

Public Shared Function ToStringAsXml(ds As DataSet) As String
    Dim sw As New StringWriter()
    ds.WriteXml(sw, XmlWriteMode.IgnoreSchema)
    Dim s As String = sw.ToString()
    Return s
End Function


使用MemoryStream对象.

在C#中:

Use a MemoryStream object.

In C#:

MemoryStream stream = new MemoryStream(); 
XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8); 
writer.WriteStartDocument(); 
myDataSet.WriteXML(stream); 



在VB中:



In VB:

Dim stream As New MemoryStream()
Dim writer As New XmlTextWriter(stream, Encoding.UTF8)
writer.WriteStartDocument()
myDataSet.WriteXML(stream)


这篇关于将DataSet对象转换为Xml字符串变量...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆