如何将数据集值存储为xmlformat字符串 [英] how to store dataset values into string in xmlformat

查看:75
本文介绍了如何将数据集值存储为xmlformat字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..
我正试图将数据集值转换为xml格式的字符串,为此我使用了以下代码.

ds1是我的数据集...

Hi..
I am tring to get the dataset values into string in xml format and for that i have used below code.

and ds1 is my dataset...

Dim strwrtxml As System.IO.StreamWriter
ds1.WriteXml(strwrtxml, XmlWriteMode.WriteSchema)
dsa = strwrtxml.ToString()



但是它不起作用并且strwrtxml得​​到null :(

请让我知道我错了...



but it''s not working and strwrtxml is geting null :(

Please let me know where i am wrong...

推荐答案

StringWriter 类在此处解释
The StringWriter class explained here http://msdn.microsoft.com/en-us/library/system.io.stringwriter.aspx[^] can be used to write DataSet values to a string in xml format. The StringWriter class uses the StringBuilder object. There are other overloads to specify the StringBuilder and FormatProvider.
Dim sw As New StringWriter()
ds1.WriteXml(sw)
Console.WriteLine(sw.ToString())


尝试一下

try this

Private Sub WriteXmlToFile(thisDataSet As DataSet)
     If thisDataSet Is Nothing Then
         Return
     End If 

    ' Create a file name to write to.
     Dim filename As String = "XmlDoc.xml"

     ' Create the FileStream to write with.
     Dim stream As New System.IO.FileStream _
        (filename, System.IO.FileMode.Create)

     ' Write to the file with the WriteXml method.
     thisDataSet.WriteXml(stream)
End Sub


这篇关于如何将数据集值存储为xmlformat字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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