DataTable

  • Thread starter Thread starter Aleksey
  • Start date Start date
A

Aleksey

Hi!

I need save data from DataTable to XML file. Is there any standard method do
that?

Thanks a lot
 
You can save all DataSet on XML File.

Dataset.WriteXml() ;

i hope it will be usefull for you.

Bruno Spinelli
 
Aleksey said:
Hi!

I need save data from DataTable to XML file. Is there any standard method do
that?

You can pass a dataset into the constructor of an XmlDataDocument. You
can then use the Save method of the XmlDataDocument. If you don't
already have it, you can get the dataset the table belongs to from the
DataSet property.
 
Hi,

I need convert data from DataTable to XML file. Understand that I can use
the following command to do it. However, there will be existing file be
created. Is there any other ways which there wont be file created? I only
need to store it in memory.
Thanks.

Cheers,
Siew Yee
 
This isn't exact since I'm doing it from memory, but it goes something
like this.

dim MS as new system.io.memorystream
Ds.WriteXML(MS)

Something close to that.
Chris
 
I need convert data from DataTable to XML file. Understand that I can use
the following command to do it. However, there will be existing file be
created. Is there any other ways which there wont be file created? I only
need to store it in memory.

DataSet.WriteXml can write to a stream, a TextWriter, an XmlWriter or a
file. You could use a MemoryStream, a StringWriter, or an XmlWriter
backed by either of them.
 
You could use XMLSerializer, and MemoryStream. As Follows(Replace Insect by
DataTable and Stream by MemoryStream):

Insect i = new Insect("Meadow Brown", 12);
XmlSerializer x = new XmlSerializer(typeof(Insect));
Stream s = File.Create("AnInsect.xml");
x.Serialize(s,i);
 
Thanks all for the information.

Below are my original codes that will create the xml file physically:

private void convertDataTableToXML()
{
// Duplicate the table and add it to a temporary DataSet
DataSet dataset = new DataSet();
DataTable datatable = premiumTable.Copy();
dataset.Tables.Add(datatable);

// Save the temporary DataSet to XML
StreamWriter streamwriter = new StreamWriter("C://XMLDoc.xml");
dataset.WriteXml(streamwriter);
streamwriter.Close();
}

However, instead of using StreamWriter, I change to MemoryStream.
Below is the codes:

MemoryStream ms = new MemoryStream();
dataset.WriteXml(ms);
ms.Close();

How to I reference the xml file created by MemoryStream for later use? Eg, I
need to extract a node value from the xml file.
Thanks.

Thanks,
Siew Yee
 
Back
Top