Click here to Skip to main content
15,909,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...

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


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

Please let me know where i am wrong...
Posted
Comments
VJ Reddy 4-Jun-12 0:59am    
Thank you for accepting the solution :)

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.
VB
Dim sw As New StringWriter()
ds1.WriteXml(sw)
Console.WriteLine(sw.ToString())
 
Share this answer
 
Comments
Maciej Los 31-May-12 11:18am    
Good answer, my 5!
VJ Reddy 31-May-12 11:25am    
Thank you, losmac :)
ssd_coolguy 1-Jun-12 5:57am    
thanks... it solved my problem. :)
VJ Reddy 1-Jun-12 6:11am    
You're welcome and thank you for the response :)
If the solution is helpful you may consider to vote and accept the solution.
try this

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900