I have a DataSet named dS in which i want to load XML.
So i would use the function dS.ReadXml();
The paramter for ReadXml function is XmlTextReader Object.
If i pass object as
ds.ReadXml(new XmlTextReader(Application.StartupPath + "\\MyDataSource.xml"));
the dataset would be loaded. But later on, i want to close that XmlTextReader object. Although i didn’t declared it with a name like
XmlTextReader reader = new XmlTextReader(somepath);
How can i close the reader???
You’ll need to use a variable, otherwise you can’t access it.
And while you are at it, use the
usingstatement:The
usingstatement automatically callsDisposeonreaderwhen exiting the scope of theusingstatement.Note: You should use
Path.Combineinstead of concatting the path yourself. Saves you a lot of trouble.