Pergunta

I'm wondering if using a stream would be faster to read an XML file and then insert into SQLCE (as opposed to reading the data from a file). So, I tried this code:

DataSet dset = new DataSet("New DataSet");
System.IO.FileStream streamRead = new System.IO.FileStream(filePathName, System.IO.FileMode.Open);
dset.ReadXml(streamRead);

...from here: http://msdn.microsoft.com/en-us/library/55hehd8c(v=vs.80).aspx

...but get these compile errors:

"Argument '1': cannot convert from 'System.IO.FileStream' to 'System.Xml.XmlReader'" -and: "The best overloaded method match for 'System.Data.DataSet.ReadXml(System.Xml.XmlReader)' has some invalid arguments"

Is it because the earliest example (the link above) is for .NET 2.0, and I am stuck with 1.0? IOW, the stream overload was not available in 1.0?

UPDATE

I also wanted to test this:

StringReader sr = new StringReader(filePathName);
DataSet dset = new DataSet("duckBills");
dset.ReadXml(sr);

...from here: http://knowdotnet.com/articles/datasetreadxml.html, but got a similar err msg; I think being stuck on .NET 1.0 is likely my problem...

Foi útil?

Solução

Use

new XmlTextReader(Stream)

DataSet dset = new DataSet("New DataSet");
using (System.IO.FileStream streamRead = new System.IO.FileStream(filePathName, System.IO.FileMode.Open))
{
    XmlTextReader reader = new XmlTextReader(streamRead);
    dset.ReadXml(reader);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top