• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Write Datatable data to XML string for database storage (.NET 1.1)

How can I write a datatable's content as an XML String for storing in a database? The only examples I found were for writing to an XML file.  
0
ZekeLA
Asked:
ZekeLA
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Hi ZekeLA,

You'll need to write the XML to file, then read that file using a TextReader or something....

    Dim tmp As String = My.Computer.FileSystem.GetTempFileName
    YourDataSet.WriteXml(tmp)
    Dim xmlString As String = IO.File.ReadAllText(tmp)

Regards,

Wayne
0
 
ZekeLAAuthor Commented:
I didn't want to write to a file. Here is the solution I found from another site:

StringWriter stringWriter = new StringWriter();
dt.WriteXml(stringWriter, XmlWriteMode.WriteSchema);
string s = stringWriter.ToString();
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now