views:

65

answers:

4

I use a DataGrid to show a xml file. The Grid's DataSource is a DataSet.(using schema)

            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream("XML_Reader.Resources.schema.xsd");
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(null, XmlReader.Create(stream));
            using (XmlReader reader = XmlReader.Create(xmlFile, settings))
            {
                newDataSet.ReadXml(reader);
            }
            dataGrid.DataSource = newDataSet;


But when reading a new xml file, i need to clear the DataSet.(newDataSet.Clear();)
Because i read 'large' (40 Mb) xml files, clearing the DataSet is very slow.

How can i speed up this clearing?
Reading the file is also slow !

On a: Intel i7 950, 8 Gb, Win7 64-bit.

+1  A: 

Why can't you just create new dataset and use that instead clearing old one? The old one will be garbage collected by .NET.

VinayC
A: 

I suggest you use a new DataSet object for each file and avoid using DataSet.Clear() altogether. Just leave the old datasets to be cleared up by the garbage collector.

Daniel Renshaw
How can i create a new Typed DataSet ?
Robertico
I need the correct datatype to sort the columns !
Robertico
Where did you get `newDataSet` from in the first place? If you newed it up and assigned the XSD yourself, just repeat the process for each file. If you're using the design-time drag-and-drop approach, you can still achieve the same effect but it's a bit more difficult.
Daniel Renshaw
I added the xsd schema and used **MSDataSetGenerator** to generate the newDataSet. (VS2008).
Robertico
Any help is appreciated. I can not find a solution creating a new Typed DataSet object.
Robertico
A: 

i think , if you employ this startgey , you may face some outofmemory exceptions also.

The size of for dataset is large more than 85K and GC will store these objects in the Large Heap and there is no way to clean this large heap.

and once you started creating new Dataset with 40 MB of data than you will face OutOfMemoryException soon.

i wouyld suggest use paging in datagrid and read lesser data and store in your memory.

saurabh
A: 

Let me answer my own question ;-))

A typed DataSet is simply a class you can instantiate like any other class.
There is no magic to anything generated by tools, those tools simply generate classes and you can use those classes the same way you use other classes.

Do NewDataSet d1 = new NewDataSet(); where you put the right class name there instead of "NewDataSet".

Robertico
-1: 1st of all, this answer is the exact same answer that you gave for another one of your own questions! http://stackoverflow.com/questions/3740486/create-new-typed-dataset-object-c/3744898#3744898 2nd, how are you addressing the speed issue with this answer? At least make up some *new* BS!
JohnB
@JohnB: The question is related. They suggest me to use a new DataSet object for each file and avoid using `DataSet.Clear();`. So the resulting question was how to create a new typed DataSet. At that point i didn't got the answer here, but wanted to share the solution. 2nd, i didn't address the speed issue (it was more a comment than a question)
Robertico